History | Edit | Delete | raw

Wiki → Public | Page index

Mumble plugin for rbot

This plugin requires the ICE bindings for ruby (see attachments).

 1 #  ----------------------------------------------------------------------------
 2 #  "THE BEER-WARE LICENSE" (Revision 42):
 3 #  <f.unglaub@gmail.com> wrote this file. As long as you retain this notice you
 4 #  can do whatever you want with this stuff. If we meet some day, and you think
 5 #  this stuff is worth it, you can buy me a beer.
 6 #  ----------------------------------------------------------------------------
 7 require 'Murmur.rb'
 8 
 9 class Mumble < Plugin
10 
11   Config.register Config::BooleanValue.new('mumble.enabled',
12                                            :default => true,
13                                            :desc => 'Enabled or not.')
14 
15   Config.register Config::StringValue.new('mumble.server.url',
16                                           :default => "Meta:tcp -h 127.0.0.1 -p 6502",
17                                           :desc => 'ICE or GLACIER2 Proxy')
18 
19   def connect
20     @ic = nil
21     begin
22       @ic = Ice::initialize(ARGV)
23       base = @ic.stringToProxy(@bot.config['mumble.server.url'])
24       @meta = Murmur::MetaPrx::checkedCast(base)
25 
26       unless @meta
27         raise "invalid proxy" 
28       end
29     rescue
30       puts $!
31       puts $!.backtrace.join("\n")
32     end
33   end
34 
35   def close
36     if @ic
37       begin
38         @ic.destroy()
39       rescue
40         puts $!
41         puts $!.backtrace.join("\n")
42       end
43     end
44   end
45 
46   def mumble_all(m, params)
47     who = m.source.nick
48 
49     connect
50 
51     output = Hash.new
52 
53     servers = @meta.getBootedServers()
54     servers.each do |server|
55       players = server.getPlayers()
56       output[server.getConf('registername')] =  players.length
57     end
58 
59     @bot.notice who, output.inspect
60     close
61   end
62 
63   def mumble(m, params)
64     who = m.source.nick
65 
66     connect
67     server = @meta.getServer(params[:nr])
68 
69     users = server.getPlayers()
70     channels = server.getChannels
71 
72     user_list=Array.new
73 
74     users.each do |id,player|
75       channel = channels[player.channel]
76       user_list << player.name+" in "+channel.name
77     end
78 
79     @bot.notice who, "Users for Server #{server.getConf('registername')}" 
80     @bot.notice who, user_list.join(", ")
81 
82     close
83   end
84 end
85 
86 plugin = Mumble.new
87 plugin.map 'mumble', :action => 'mumble_all'
88 plugin.map 'mumble show :nr',
89 :action => 'mumble',
90 :requirements => { :nr => /\d+/ }

Attached items:


Last Edit: June 30, 2009 20:16 by ueber