]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
basics: implement a channel list status query
authorRobin H. Johnson <robbat2@gentoo.org>
Sat, 13 Mar 2010 09:31:28 +0000 (09:31 +0000)
committerRobin H. Johnson <robbat2@gentoo.org>
Sun, 14 Mar 2010 21:08:48 +0000 (21:08 +0000)
This gets the list of channels we think we are in (not what the server says we are in).

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
lib/rbot/core/basics.rb

index d5ff5fb93e3b7feb20993c544c879bd8e8dbf18a..24d45419ab310c8c9ccdd1628431bfc676f2de7d 100644 (file)
@@ -69,6 +69,20 @@ class BasicsModule < CoreBotModule
     end
   end
 
+  def bot_channel_list(m, param)
+    ret = _('I am in: ')
+    # sort the channels by the base name and then map with prefixes for the
+    # mode and display.
+    ret << @bot.channels.compact.sort { |a,b|
+        a.name.downcase <=> b.name.downcase
+    }.map { |c|
+        c.modes_of(@bot.myself).map{ |mo|
+          m.server.prefix_for_mode(mo)
+        }.to_s + c.name
+    }.join(', ')
+    m.reply ret
+  end
+
   def bot_quit(m, param)
     @bot.quit param[:msg].to_s
   end
@@ -212,6 +226,9 @@ basics.map "part :chan",
   :action => 'bot_part',
   :defaults => {:chan => nil},
   :auth_path => 'move'
+basics.map "channels",
+  :action => 'bot_channel_list',
+  :auth_path => 'move'
 basics.map "hide",
   :action => 'bot_hide',
   :auth_path => 'move'