+#-- vim:sw=2:et
+#++
+#
+# :title: rbot core
+
require 'thread'
require 'etc'
class Exception
def pretty_print(q)
q.group(1, "#<%s: %s" % [self.class, self.message], ">") {
- q.seplist(self.backtrace, lambda { "\n" }) { |v| v } if self.backtrace
+ if self.backtrace and not self.backtrace.empty?
+ q.text "\n"
+ q.seplist(self.backtrace, lambda { q.text "\n" } ) { |l| q.text l }
+ end
}
end
end
# handles them or passes them to plugins, and contains core functionality.
class Bot
COPYRIGHT_NOTICE = "(c) Tom Gilbert and the rbot development team"
+ SOURCE_URL = "http://linuxbrit.co.uk/rbot"
# the bot's Auth data
attr_reader :auth
unless ignored
@plugins.delegate "listen", m
+ @plugins.delegate("ctcp_listen", m) if m.ctcp
@plugins.privmsg(m) if m.address?
- if not m.replied
+ if not m.replied
@plugins.delegate "unreplied", m
end
end
sendmsg "PRIVMSG", where, message, options
end
+ def ctcp_notice(where, command, message, options={})
+ return if where.kind_of?(Channel) and quiet_on?(where)
+ sendmsg "NOTICE", where, "\001#{command} #{message}\001", options
+ end
+
+ def ctcp_say(where, command, message, options={})
+ return if where.kind_of?(Channel) and quiet_on?(where)
+ sendmsg "PRIVMSG", where, "\001#{command} #{message}\001", options
+ end
+
# perform a CTCP action with message +message+ to channel/nick +where+
def action(where, message, options={})
- return if where.kind_of?(Channel) and quiet_on?(where)
- mchan = options.fetch(:queue_channel, nil)
- mring = options.fetch(:queue_ring, nil)
- if mchan
- chan = mchan
- else
- chan = where
- end
- if mring
- ring = mring
- else
- case where
- when User
- ring = 1
- else
- ring = 2
- end
- end
- # FIXME doesn't check message length. Can we make this exploit sendmsg?
- sendq "PRIVMSG #{where} :\001ACTION #{message}\001", chan, ring
- case where
- when Channel
- irclog "* #{myself} #{message}", where
- else
- irclog "* #{myself}[#{where}] #{message}", where
- end
+ ctcp_say(where, 'ACTION', message, options)
end
# quick way to say "okay" (or equivalent) to +where+