Sha256: c5e7597a2af4662e59893d5b47280ce00468cb25419409839dff2d73ac8cc950
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
# # Actions are run in the context of a Scamp::Action. # This allows us to make channel, nick etc. methods # available on a per-message basis # # {:room_id=>401839, :created_at=>"2011/09/10 00:23:19 +0000", :body=>"something", :id=>408089344, :user_id=>774016, :type=>"TextMessage"} class Scamp class Action attr :matches, :bot def initialize(bot, action, message) @bot = bot @action = action @message = message end def matches=(match) @matches = match[1..-1] match.names.each do |name| name_s = name.to_sym self.class.send :define_method, name_s do match[name_s] end end end def channel puts "Need the real channel name at #{__FILE__}:#{__LINE__}" @message[:room_id] end def user bot.username_for(@message[:user_id]) end def user_id @message[:user_id] end def message @message[:body] end def run self.instance_eval &@action end private def say(msg, channel_id_or_name = channel) bot.say(msg, channel_id_or_name) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
scamp-0.0.1 | lib/scamp/action.rb |