Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

memo on join

  • Loading branch information...
commit bdbe03fbc591f465ae7b280167f838b2278ba55b 1 parent 1c5fcfd
@jmettraux authored
Showing with 46 additions and 6 deletions.
  1. +2 −0  TODO.txt
  2. +44 −6 ilog.rb
View
2  TODO.txt
@@ -4,5 +4,7 @@
[o] pong
[o] don't log empty lines (after commands)
[o] don't eat initial ":"
+[o] memo on join
+
[ ] :freenode-connect!freenode@freenode/bot/connect PRIVMSG nick :VERSION
View
50 ilog.rb
@@ -64,9 +64,14 @@ def initialize (opts)
#
# history regex
- @lhistory = @opts[:admins] ?
- /^:(.*)!(.*) PRIVMSG #{@opts[:nick]} :history( .*)?$/ :
- nil
+ @lhistory = @admins.empty? ?
+ nil :
+ /^:(.*)!(.*) PRIVMSG #{@opts[:nick]} :history( .*)?$/
+
+ #
+ # memos
+
+ @memos = @admins.empty? ? nil : {}
#
# select loop (listening)
@@ -111,6 +116,11 @@ def determine_target_file
end
end
+ def stime
+
+ Time.now.utc.strftime('%F %T utc')
+ end
+
def send (s)
#puts "out> #{s}"
@@ -119,10 +129,12 @@ def send (s)
LREG = /^:(.*)!(.*) PRIVMSG (#[^ ]+?) :(.*)$/
LPING = /^PING :(.*)$/i
+ LMEMO = /^memo ([^ :]+) *:(.+)$/
+ LJOIN = /^:(.*)!(.*) JOIN /
def receive_line (l)
- #puts l
+ puts l
l = l.strip
@@ -133,6 +145,8 @@ def receive_line (l)
return
end
+ # history
+
if @lhistory && (m = @lhistory.match(l)) && @admins.include?(m[1])
offset = (m[3] || 10).to_i rescue 10
@@ -145,11 +159,35 @@ def receive_line (l)
end
end
+ # on join
+
+ if m = LJOIN.match(l)
+
+ (@memos.delete(m[1]) || []).each do |author, time, memo|
+ sleep 0.300
+ msg = "#{m[1]}: (memo from #{author} at #{time}) #{memo}"
+ send "PRIVMSG ##{@opts[:channel]} :#{msg}"
+ @mutex.synchronize { @file.puts("#{stime} #{@opts[:nick]}: #{msg}") }
+ end
+ end
+
+ # ...
+
+ m = LREG.match(l)
+
+ # memo
+
+ if m and @admins.include?(m[1]) and mm = LMEMO.match(m[4])
+ (@memos[mm[1]] ||= []) << [ m[1], Time.now.to_s, mm[2].strip ]
+ end
+
+ # regular logging
+
@mutex.synchronize do
- @file.write("#{Time.now.utc.strftime('%F %T utc')} ")
+ @file.write("#{stime} ")
- if m = LREG.match(l)
+ if m
ll = "#{m[1]}: #{m[4]}"
@history << ll
@file.write(ll)
Please sign in to comment.
Something went wrong with that request. Please try again.