Created
June 24, 2011 14:09
-
-
Save shokai/1044838 to your computer and use it in GitHub Desktop.
use dropbox as a chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
## dropboxの共有フォルダでチャットするツールです | |
## drochan -> 発言表示 | |
## drochan ほむほむ -> 「ほむほむ」と発言 | |
DIR = "#{ENV['HOME']}/Dropbox/drochan" | |
user = ENV['USER'] | |
# user = "your-name" | |
EXT = 'drcn' | |
Dir.glob("#{DIR}/#{user}.#{EXT}/*").each{|f| | |
if Time.now.to_i-File.mtime(f).to_i > 60*60*24*3 # 3day | |
File.delete(f) | |
end | |
} | |
if ARGV.size < 1 | |
Dir.glob("#{DIR}/*.#{EXT}/*").sort{|a,b| | |
File.mtime(b) <=> File.mtime(a) | |
}[0...60].reverse.each{|i| | |
name = i.scan(/([^\/]+)\.#{EXT}\/[^\/]+/).first.first | |
msg = i.scan(/\/([^\/]+)$/).first.first | |
puts "#{name} - #{msg} at #{File.mtime(i)}" | |
} | |
exit 0 | |
end | |
Dir.mkdir("#{DIR}/#{user}.#{EXT}") unless File.exists?("#{DIR}/#{user}.#{EXT}") | |
msg = ARGV.join(' ') | |
fname = "#{DIR}/#{user}.#{EXT}/#{msg}" | |
if File.exists?(fname) | |
File.open(fname,'w+'){|f| | |
f.puts Time.now | |
} | |
else | |
File.open(fname,'w+') | |
end | |
puts "=> #{msg}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment