Class: Svenbot::Bot
Instance Method Summary collapse
- #cmd_help(jid, unused) ⇒ Object
-
#cmd_list(jid, unused) ⇒ Object
Return a list of paths you are interested in commits for.
- #cmd_register(jid, path) ⇒ Object
-
#cmd_unregister(jid, path) ⇒ Object
Remove messages about commits to a certain
path
. -
#commit_messages(commit) ⇒ Object
Return a list of messages to send out for
commit
. - #dispatch_cmd(msg) ⇒ Object
-
#initialize(repo) ⇒ Bot
constructor
A new instance of Bot.
Methods included from Message
Constructor Details
#initialize(repo) ⇒ Bot
Returns a new instance of Bot.
8 9 10 11 |
# File 'lib/svenbot/bot.rb', line 8 def initialize(repo) @repo = repo @user_manager = UserManager.new end |
Instance Method Details
#cmd_help(jid, unused) ⇒ Object
23 24 25 26 27 |
# File 'lib/svenbot/bot.rb', line 23 def cmd_help(jid, unused) commands = self.class.public_instance_methods.grep(/^cmd_/). collect { |m| m.sub( /^cmd_/, '' ) }.sort.join(', ') return ("available commands: #{commands}").set_to(jid) end |
#cmd_list(jid, unused) ⇒ Object
Return a list of paths you are interested in commits for.
38 39 40 41 42 43 44 45 46 |
# File 'lib/svenbot/bot.rb', line 38 def cmd_list(jid, unused) paths = @user_manager.paths_for(jid) if paths.empty? msg = 'You are not listening to any commits' else msg = "You are listening for commits to: #{paths.join(', ')}" end return (msg).set_to(jid) end |
#cmd_register(jid, path) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/svenbot/bot.rb', line 29 def cmd_register(jid, path) @user_manager.register jid, path paths = @user_manager.paths_for jid msg = "You will get commits for: #{paths.join(', ')}" return (msg).set_to(jid) end |
#cmd_unregister(jid, path) ⇒ Object
Remove messages about commits to a certain path
. If not specified, path
defaults to “/”.
50 51 52 53 54 |
# File 'lib/svenbot/bot.rb', line 50 def cmd_unregister(jid, path) @user_manager.unregister jid, path msg = "You will no longer get commits for: #{path}" return (msg).set_to(jid) end |
#commit_messages(commit) ⇒ Object
Return a list of messages to send out for commit
.
57 58 59 60 61 62 |
# File 'lib/svenbot/bot.rb', line 57 def (commit) msg = "#{commit.user} committed #{commit.id}: #{commit.}" @user_manager.users_for(commit.path_prefix).collect do |jid| (msg).set_to(jid) end end |
#dispatch_cmd(msg) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/svenbot/bot.rb', line 13 def dispatch_cmd(msg) cmd, args = msg.body.split(' ', 2) method = "cmd_#{cmd}".to_sym if self.class.method_defined? method return self.send(method, msg.from, args) else return ("unknown command '#{cmd}'").set_to(msg.from) end end |