Skip to content
Browse files

Add ir bot, remove current_user, that's not on the right object

  • Loading branch information...
1 parent d4b0e04 commit 3aefe4d7b0a71e78cfd531b203fbb79f03a87735 @raggi committed
Showing with 39 additions and 4 deletions.
  1. +0 −4 lib/talker_bot.rb
  2. +39 −0 lib/talker_bot/bots/ir_bot.rb
View
4 lib/talker_bot.rb
@@ -47,10 +47,6 @@ def plugin(plugin)
end
alias use plugin
- def current_user
- @connection.current_user
- end
-
def connect
@connection = Talker.connect(@config) do |client|
TALKER_CALLBACKS.each do |cb|
View
39 lib/talker_bot/bots/ir_bot.rb
@@ -0,0 +1,39 @@
+require 'talker_bot/autorun'
+require 'ir'
+
+class IrBot
+ attr_accessor :bot
+
+ def initialize
+ @ir = Ir.new(:output => self, :inspector => method(:inspector))
+ @users = Hash.new { |h,k| h[k] = '' }
+ end
+
+ def print(*args)
+ bot.send_message args.join("\n")
+ end
+
+ def on_message(sender, content)
+ return if sender == bot.current_user
+ @users[sender] << content
+ return unless syntax_ok?(@users[sender])
+ @ir << @users[sender]
+ @users[sender] = ''
+ end
+
+ def on_leave(*users)
+ users.each { |u| @users.delete(u) }
+ end
+
+ def syntax_ok?(buffer)
+ catch(:ok) { eval("BEGIN{throw:ok,true}; _ = #{buffer}") }
+ rescue SyntaxError
+ false
+ end
+
+ def inspector(ir, o)
+ bot.send_message o.inspect
+ end
+end
+
+use IrBot.new

0 comments on commit 3aefe4d

Please sign in to comment.
Something went wrong with that request. Please try again.