ratchet 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/gem_bin/ratchet +23 -0
- data/lib/ratchet.rb +613 -0
- data/lib/ratchet/aliases.rb +106 -0
- data/lib/ratchet/bufferparser.rb +409 -0
- data/lib/ratchet/commandbuffer.rb +66 -0
- data/lib/ratchet/commandparser.rb +668 -0
- data/lib/ratchet/configuration.rb +278 -0
- data/lib/ratchet/connections.rb +403 -0
- data/lib/ratchet/constants.rb +111 -0
- data/lib/ratchet/contrib/instance_exec.rb +21 -0
- data/lib/ratchet/eventparser.rb +486 -0
- data/lib/ratchet/gtk/bufferlistview.rb +514 -0
- data/lib/ratchet/gtk/bufferview.rb +167 -0
- data/lib/ratchet/gtk/configwindow.rb +229 -0
- data/lib/ratchet/gtk/connectionwindow.rb +218 -0
- data/lib/ratchet/gtk/keybinding.rb +356 -0
- data/lib/ratchet/gtk/linkwindow.rb +137 -0
- data/lib/ratchet/gtk/mainwindow.rb +504 -0
- data/lib/ratchet/gtk/networkpresenceconf.rb +567 -0
- data/lib/ratchet/gtk/pluginconfig.rb +94 -0
- data/lib/ratchet/gtk/pluginwindow.rb +146 -0
- data/lib/ratchet/gtk/userlistview.rb +161 -0
- data/lib/ratchet/help.rb +64 -0
- data/lib/ratchet/items.rb +271 -0
- data/lib/ratchet/lines.rb +63 -0
- data/lib/ratchet/networks.rb +652 -0
- data/lib/ratchet/plugins.rb +616 -0
- data/lib/ratchet/queue.rb +47 -0
- data/lib/ratchet/ratchet-version.rb +21 -0
- data/lib/ratchet/replies.rb +134 -0
- data/lib/ratchet/replyparser.rb +441 -0
- data/lib/ratchet/tabcomplete.rb +98 -0
- data/lib/ratchet/users.rb +237 -0
- data/lib/ratchet/utils.rb +178 -0
- data/share/defaults.yaml +169 -0
- data/share/glade/config.glade +2634 -0
- data/share/glade/connect.glade +950 -0
- data/share/glade/keybindings.glade +109 -0
- data/share/glade/linkwindow.glade +188 -0
- data/share/glade/mainwindow.glade +335 -0
- data/share/glade/network-presences.glade +1373 -0
- data/share/glade/pluginconf.glade +97 -0
- data/share/glade/plugins.glade +360 -0
- data/share/plugins/colorewrite.rb +193 -0
- data/share/plugins/highlighter.rb +115 -0
- data/share/plugins/mpdplay.rb +123 -0
- data/share/plugins/numberswitcher.rb +30 -0
- data/share/plugins/sysinfo.rb +82 -0
- metadata +96 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
This file is part of the Ratchet project, a client for Icecap.
|
|
3
|
+
Copyright (C) 2005-6 Andrew Thompson
|
|
4
|
+
|
|
5
|
+
This program is free software; you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation; either version 2 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program; if not, write to the Free Software
|
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
+
=end
|
|
19
|
+
|
|
20
|
+
#### commandbuffer.rb ####
|
|
21
|
+
# A simple command buffer used for input history
|
|
22
|
+
####
|
|
23
|
+
|
|
24
|
+
module Ratchet
|
|
25
|
+
class CommandBuffer
|
|
26
|
+
attr_accessor :currentcommand
|
|
27
|
+
def initialize(config)
|
|
28
|
+
@config = config
|
|
29
|
+
@commandbuffer = []
|
|
30
|
+
@currentcommand = ''
|
|
31
|
+
@commandindex = 0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#add a command to the command buffer
|
|
35
|
+
def add_command(string, increment=true)
|
|
36
|
+
if string.length == 0 or string == @commandbuffer[@commandindex]
|
|
37
|
+
@commandindex =@commandbuffer.length
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
@commandbuffer << string
|
|
41
|
+
if @commandbuffer.length > @config['commandbuffersize'].to_i
|
|
42
|
+
@commandbuffer.unshift
|
|
43
|
+
end
|
|
44
|
+
@commandindex =@commandbuffer.length
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#get the last command in the command buffer
|
|
48
|
+
def last_command
|
|
49
|
+
@commandindex -=1 if @commandindex > 0
|
|
50
|
+
command = @commandbuffer[@commandindex]
|
|
51
|
+
command ||= ''
|
|
52
|
+
return command
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#get the next command in the command buffer
|
|
56
|
+
def next_command
|
|
57
|
+
@commandindex +=1
|
|
58
|
+
if @commandindex >= @commandbuffer.length
|
|
59
|
+
@commandindex = @commandbuffer.length if @commandindex > @commandbuffer.length
|
|
60
|
+
return ''
|
|
61
|
+
else
|
|
62
|
+
return @commandbuffer[@commandindex]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
This file is part of the Ratchet project, a client for Icecap.
|
|
3
|
+
Copyright (C) 2005-6 Andrew Thompson
|
|
4
|
+
|
|
5
|
+
This program is free software; you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation; either version 2 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program; if not, write to the Free Software
|
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
+
=end
|
|
19
|
+
|
|
20
|
+
#### commandparser.rb ####
|
|
21
|
+
# Contains additional Main methods that define commands of the format cmd_<commandname>
|
|
22
|
+
# the command_parse method finds the appropiate method and passes the input to it
|
|
23
|
+
# callbacks are also honored for these methods
|
|
24
|
+
####
|
|
25
|
+
|
|
26
|
+
module Ratchet
|
|
27
|
+
class Main
|
|
28
|
+
def command_parse(message, target)
|
|
29
|
+
|
|
30
|
+
#TODO - fix this?
|
|
31
|
+
#~ if network and !network.loggedin
|
|
32
|
+
#~ throw_message('buffering command '+message)
|
|
33
|
+
#~ network.bufferedcommands.push(message)
|
|
34
|
+
#~ return
|
|
35
|
+
#~ end
|
|
36
|
+
|
|
37
|
+
# message = check_aliases(message)
|
|
38
|
+
|
|
39
|
+
if /^(\/\w+)(?: (.+)|)/.match(message)
|
|
40
|
+
command = $1
|
|
41
|
+
arguments = $2
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if command and command[0].chr == '/'
|
|
45
|
+
if result = @config['aliases'].detect{|k,v| '/'+k.downcase == message[0..k.length].downcase}
|
|
46
|
+
Alias.new(result[1], arguments, target).commands.each{|x|sleep 0.1;command_parse(x, target)}
|
|
47
|
+
return
|
|
48
|
+
else
|
|
49
|
+
cmd = command[1, command.length].downcase
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
begin
|
|
54
|
+
if cmd and self.respond_to?('cmd_'+cmd)
|
|
55
|
+
res = callback('cmd_'+cmd, arguments, target)
|
|
56
|
+
return if res === true
|
|
57
|
+
self.send('cmd_'+cmd, *res)
|
|
58
|
+
#unhandled command
|
|
59
|
+
elsif cmd
|
|
60
|
+
# puts cmd
|
|
61
|
+
# puts caller
|
|
62
|
+
res = callback(:command_missing, cmd, arguments, target)
|
|
63
|
+
return if res === true
|
|
64
|
+
command_missing(*res)
|
|
65
|
+
else
|
|
66
|
+
res = callback('cmd_message', message, target)
|
|
67
|
+
self.send('cmd_message', *res)
|
|
68
|
+
end
|
|
69
|
+
#rescue any exceptions...
|
|
70
|
+
rescue =>exception
|
|
71
|
+
puts 'Error parsing commmand : '+$!
|
|
72
|
+
puts exception.backtrace
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#/exec support, -o makes it output to the channel
|
|
77
|
+
help :cmd_exec, "executes a command, the -o switch makes it output to the channel"
|
|
78
|
+
def cmd_exec(message, target)
|
|
79
|
+
return unless message
|
|
80
|
+
|
|
81
|
+
output = false
|
|
82
|
+
|
|
83
|
+
if message[0,2] == '-o'
|
|
84
|
+
output = true
|
|
85
|
+
message = message[3..-1]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
res = `#{message}`
|
|
89
|
+
res.chomp
|
|
90
|
+
if $? == 0 and res
|
|
91
|
+
res.split("\n").each do |msg|
|
|
92
|
+
if output
|
|
93
|
+
if target.class == ChannelBuffer or target.class == ChatBuffer
|
|
94
|
+
reply = send_command('message'+rand(100).to_s, "msg;#{target.identifier_string};#{escape(msg)}")
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
lineref = target.send_user_event({'msg' => msg}, EVENT_USERMESSAGE)
|
|
98
|
+
reply.lineref = lineref if reply
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
help :cmd_message, "Sends a message to the channel"
|
|
105
|
+
def cmd_message(message, target)
|
|
106
|
+
#its not a command, treat as a message
|
|
107
|
+
if target.respond_to? :username
|
|
108
|
+
#puts message
|
|
109
|
+
messages = message.split("\n")
|
|
110
|
+
messages.each do |message|
|
|
111
|
+
if target.class == ChannelBuffer
|
|
112
|
+
rep = send_command('message'+rand(100).to_s, 'msg;network='+target.network.name+';channel='+target.name+';msg='+escape(message)+";mypresence="+target.presence)
|
|
113
|
+
elsif target.class == ChatBuffer
|
|
114
|
+
rep = send_command('message'+rand(100).to_s, 'msg;network='+target.network.name+';presence='+target.name+';msg='+escape(message)+";mypresence="+target.presence)
|
|
115
|
+
end
|
|
116
|
+
line = {}
|
|
117
|
+
line[PRESENCE] = target.presence
|
|
118
|
+
line[MSG] = message
|
|
119
|
+
lineref = target.send_user_event(line, EVENT_USERMESSAGE)
|
|
120
|
+
rep.lineref = lineref if rep
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
#line = {}
|
|
124
|
+
throw_error('Invalid server command')
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
#/join command
|
|
129
|
+
help :cmd_join, "Join a channel. usage: /join <channel>"
|
|
130
|
+
def cmd_join(arguments, target)
|
|
131
|
+
return unless target
|
|
132
|
+
# puts arguments, target, target.joined?
|
|
133
|
+
if !arguments and target.respond_to? :join and !target.joined?
|
|
134
|
+
# puts target.name
|
|
135
|
+
arguments = target.name
|
|
136
|
+
end
|
|
137
|
+
send_command('join', "channel join;#{target.network.identifier_string};channel=#{arguments}") if arguments
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
#/server command
|
|
141
|
+
help :cmd_server, "Define a server. usage: /server <name>:<protocol>:<address>[:<port>]"
|
|
142
|
+
def cmd_server(arguments, target)
|
|
143
|
+
if arguments =~ /^([a-zA-Z0-9_\-]+):([a-zA-Z]+):([a-zA-Z0-9_.\-]+)(?:$|:(\d+))/
|
|
144
|
+
network_add($1, $2, $3, $4)
|
|
145
|
+
else
|
|
146
|
+
throw_error('Usage: /server <name>:<protocol>:<address>[:<port>]')
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
#/connect command
|
|
151
|
+
help :cmd_connect, "Connect to a network. Usage: /connect <Network> <Presence>"
|
|
152
|
+
def cmd_connect(arguments, target)
|
|
153
|
+
unless arguments
|
|
154
|
+
throw_error('Specify a network to connect to.')
|
|
155
|
+
return
|
|
156
|
+
end
|
|
157
|
+
network, presence = arguments.split(' ', 2)
|
|
158
|
+
|
|
159
|
+
unless presence
|
|
160
|
+
#presence = $config['presence']
|
|
161
|
+
throw_error('Specify a presence to use.')
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
if presence_add(network, presence)
|
|
165
|
+
network_connect(network, presence)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
#/disconnect command
|
|
170
|
+
help :cmd_disconnect, "Disconnect from a network. Usage: /disconnect [Network]"
|
|
171
|
+
def cmd_disconnect(arguments, target)
|
|
172
|
+
if target.respond_to? :network and target.network.connected?
|
|
173
|
+
send_command('disconnect', "presence disconnect;#{target.network.identifier_string}")
|
|
174
|
+
elsif !target.network.connected?
|
|
175
|
+
throw_error('Cannot disconnect, network already disconnected')
|
|
176
|
+
else
|
|
177
|
+
throw_error('/disconnect does not function in this tab without a network argument')
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
# unless target.respond
|
|
181
|
+
# if !arguments
|
|
182
|
+
# throw_error('/disconnect does not function in this tab without a network argument')
|
|
183
|
+
# return
|
|
184
|
+
# end
|
|
185
|
+
# end
|
|
186
|
+
|
|
187
|
+
# if network and !arguments
|
|
188
|
+
# servername = network.name
|
|
189
|
+
# presence = network.presence
|
|
190
|
+
# else
|
|
191
|
+
# servername, presence = arguments.split(' ', 2)
|
|
192
|
+
# end
|
|
193
|
+
|
|
194
|
+
# if presence
|
|
195
|
+
# elsif target.network.name == networkname
|
|
196
|
+
# presence = target.presence
|
|
197
|
+
# else
|
|
198
|
+
# results = @serverlist.get_network_by_name(networkname)
|
|
199
|
+
|
|
200
|
+
# if results
|
|
201
|
+
# results.delete_if {|server| !server.connected}
|
|
202
|
+
# end
|
|
203
|
+
|
|
204
|
+
# if results and results.length == 1
|
|
205
|
+
# presence = results[0].presence
|
|
206
|
+
# elsif results and results.length > 1
|
|
207
|
+
# throw_error('Multiple networks named '+servername+' please specify a presence')
|
|
208
|
+
# else
|
|
209
|
+
# throw_error('No network named '+servernames)
|
|
210
|
+
# end
|
|
211
|
+
# end
|
|
212
|
+
|
|
213
|
+
# if presence and servername
|
|
214
|
+
# send_command('disconnect'+servername, "presence disconnect;network="+servername+";mypresence="+presence)
|
|
215
|
+
# server = @serverlist[servername, presence]
|
|
216
|
+
# server.disconnect
|
|
217
|
+
# #
|
|
218
|
+
# #server.close if server
|
|
219
|
+
# end
|
|
220
|
+
# end
|
|
221
|
+
|
|
222
|
+
#/part command
|
|
223
|
+
help :cmd_part, "Leave a channel. Usage: /part [channel]"
|
|
224
|
+
def cmd_part(arguments, target)
|
|
225
|
+
unless target.respond_to? :topic
|
|
226
|
+
throw_error('/part does not function in this tab.')
|
|
227
|
+
return
|
|
228
|
+
end
|
|
229
|
+
if arguments
|
|
230
|
+
channame = arguments.split(' ')
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
if channame
|
|
234
|
+
send_command('part', "channel part;#{target.network.identifier_string};channel="+channame[0])
|
|
235
|
+
elsif target
|
|
236
|
+
send_command('part', "channel part;#{target.identifier_string}")
|
|
237
|
+
else
|
|
238
|
+
error_throw('Part requires a channel argument or it must be called from a channel tab.')
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
help :cmd_close, "Close current buffer, will close all children of current buffer"
|
|
243
|
+
def cmd_close(arguments, target)
|
|
244
|
+
if target.respond_to? :connect
|
|
245
|
+
send_command('disconnect', "presence disconnect;#{target.identifier_string}")
|
|
246
|
+
@buffers.values.select{|x| x.network == target}.each do |buffer|
|
|
247
|
+
buffer.close
|
|
248
|
+
end
|
|
249
|
+
elsif target.respond_to? :topic
|
|
250
|
+
send_command('part', "channel part;#{target.identifier_string}")
|
|
251
|
+
target.close
|
|
252
|
+
else
|
|
253
|
+
target.close
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
#/quit command
|
|
258
|
+
help :cmd_quit, "Quit Ratchet"
|
|
259
|
+
def cmd_quit(arguments, target)
|
|
260
|
+
send_command('quit', 'quit')
|
|
261
|
+
Gtk.main_quit
|
|
262
|
+
quit
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
#/shutdown command
|
|
266
|
+
help :cmd_shutdown, "Kill Icecapd and quit Ratchet"
|
|
267
|
+
def cmd_shutdown(arguments, target)
|
|
268
|
+
send_command('shutdown', 'shutdown')
|
|
269
|
+
Gtk.main_quit
|
|
270
|
+
quit
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
help :cmd_topic, "Get or print the topic. Usage: /topic [newtopic]"
|
|
274
|
+
def cmd_topic(arguments, target)
|
|
275
|
+
unless target.kind_of? ChannelBuffer
|
|
276
|
+
error_throw('/topic only functions in a channel tab')
|
|
277
|
+
return
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
if arguments
|
|
281
|
+
#update the topic
|
|
282
|
+
send_command('topicchange', 'channel change;network='+target.network.name+';mypresence='+target.network.presence+';channel='+target.name+';topic='+escape(arguments))
|
|
283
|
+
else
|
|
284
|
+
#print the topic
|
|
285
|
+
event = {'init' => true, 'line'=>1, CHANNEL=>target.name, TOPIC=>target.topic}
|
|
286
|
+
target.send_user_event(event, EVENT_TOPIC)
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
#/ruby command
|
|
292
|
+
help :cmd_ruby, "Blindly execute ruby code"
|
|
293
|
+
def cmd_ruby(arguments, target)
|
|
294
|
+
unless arguments
|
|
295
|
+
throw_error('Give me some code to execute')
|
|
296
|
+
return
|
|
297
|
+
end
|
|
298
|
+
throw_message('possibly evil ruby code inputted, blindly executing')
|
|
299
|
+
eval(arguments)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
#/raw command
|
|
303
|
+
help :cmd_raw, "Send raw icecap messages to icecapd"
|
|
304
|
+
def cmd_raw(arguments, target)
|
|
305
|
+
unless arguments
|
|
306
|
+
throw_error('Specify a string to send to the server')
|
|
307
|
+
return
|
|
308
|
+
end
|
|
309
|
+
throw_message('Sent raw command "'+arguments+'" to irssi2 directly')
|
|
310
|
+
send_command('raw', arguments)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
#/nick command
|
|
314
|
+
help :cmd_nick, "Change your nickname. Usage: /nick <nickname>"
|
|
315
|
+
def cmd_nick(arguments, target)
|
|
316
|
+
unless target and arguments
|
|
317
|
+
unless target.respond_to? :username
|
|
318
|
+
throw_error('/nick command does not function in this tab.')
|
|
319
|
+
return
|
|
320
|
+
end
|
|
321
|
+
if !arguments
|
|
322
|
+
throw_error('Usage: /nick <nickname>')
|
|
323
|
+
return
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
name, bleh = arguments.split(' ', 2)
|
|
327
|
+
send_command('nick'+name, "presence change;#{target.network.identifier_string};name=#{name}")
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
#/whois command
|
|
331
|
+
help :cmd_whois, "Get the whois info on somebody"
|
|
332
|
+
def cmd_whois(arguments, target)
|
|
333
|
+
unless target.respond_to? :network
|
|
334
|
+
throw_error('/whois command does not function in this tab.')
|
|
335
|
+
return
|
|
336
|
+
end
|
|
337
|
+
if arguments
|
|
338
|
+
name, bleh = arguments.split(' ', 2)
|
|
339
|
+
else
|
|
340
|
+
name = target.username
|
|
341
|
+
end
|
|
342
|
+
send_command('whois'+name, "presence status;#{target.network.identifier_string};presence=#{name}")
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
#/msg command
|
|
346
|
+
help :cmd_msg, "Message another user. Usage: /msg <username> <message>"
|
|
347
|
+
def cmd_msg(arguments, target)
|
|
348
|
+
unless target.respond_to? :presence
|
|
349
|
+
throw_error('/msg does not function in this tab')
|
|
350
|
+
return
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
if arguments
|
|
354
|
+
nick,msgs = arguments.split(' ', 2)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
if nick and msgs
|
|
358
|
+
messages = msgs.split("\n")
|
|
359
|
+
messages.each do |message|
|
|
360
|
+
send_command('msg'+rand(100).to_s, 'msg;network='+target.network.name+';presence='+nick+';msg='+message+";mypresence="+target.presence)
|
|
361
|
+
if buffer = find_buffer(target.network.name, target.presence, nil, nick)
|
|
362
|
+
buffer.send_user_event({'msg'=>message}, EVENT_USERMESSAGE)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
else
|
|
366
|
+
throw_error('/msg requires a username and a message')
|
|
367
|
+
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
help :cmd_query, "Open a new chat buffer, and optionaly message the user. Usage: /query <username> [message]"
|
|
372
|
+
def cmd_query(arguments, target)
|
|
373
|
+
if arguments
|
|
374
|
+
nick,msgs = arguments.split(' ', 2)
|
|
375
|
+
chat = add_buffer(target.network.name, target.presence, nil, nick) if nick
|
|
376
|
+
# puts chat
|
|
377
|
+
cmd_msg(arguments, chat) if msgs and chat
|
|
378
|
+
# chat.send_user_event({'msg'=>msgs}, EVENT_USERMESSAGE)
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
help :cmd_me, "Does an emote"
|
|
384
|
+
def cmd_me(arguments, target)
|
|
385
|
+
unless target.respond_to? :users and target.network != target
|
|
386
|
+
throw_error('/me does not function in this tab')
|
|
387
|
+
return
|
|
388
|
+
end
|
|
389
|
+
reply = send_command('message'+rand(100).to_s, "msg;#{target.identifier_string};msg=#{escape(arguments)};type=action")
|
|
390
|
+
lineref = target.send_user_event({'msg'=>arguments, 'type'=>'action'}, EVENT_USERMESSAGE)
|
|
391
|
+
reply.lineref = lineref
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
help :cmd_networks, "List all defined networks"
|
|
395
|
+
def cmd_networks(arguments, target)
|
|
396
|
+
lines = ['Defined networks:']
|
|
397
|
+
@networks.list.each {|network| lines.push(network.name+' - '+network.protocol)}
|
|
398
|
+
|
|
399
|
+
lines.push(' ')
|
|
400
|
+
|
|
401
|
+
lines.each do |line|
|
|
402
|
+
event = {'msg' => line}
|
|
403
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
help :cmd_protocols, "List all supported protocols"
|
|
408
|
+
def cmd_protocols(arguments, target)
|
|
409
|
+
lines = ['Defined protocols']
|
|
410
|
+
@protocols.list.each {|protocol| lines.push("#{protocol.name} - #{protocol.charsets_in.join(', ')}, #{protocol.charset_out}") }
|
|
411
|
+
|
|
412
|
+
lines.push(' ')
|
|
413
|
+
|
|
414
|
+
lines.each do |line|
|
|
415
|
+
event = {'msg' => line}
|
|
416
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
417
|
+
end
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
help :cmd_gateways, "List all defined gateways"
|
|
421
|
+
def cmd_gateways(arguments, target)
|
|
422
|
+
lines = ['Defined gateways:']
|
|
423
|
+
|
|
424
|
+
#~ @serverlist.servers.each do |server|
|
|
425
|
+
#~ network, presence = server.getnetworkpresencepair
|
|
426
|
+
#~ if server.connected
|
|
427
|
+
#~ lines.push(network+' - '+presence+' - Connected')
|
|
428
|
+
#~ else
|
|
429
|
+
#~ lines.push(network+' - '+presence)
|
|
430
|
+
#~ end
|
|
431
|
+
#~ end
|
|
432
|
+
|
|
433
|
+
@networks.list.each do |network|
|
|
434
|
+
network.gateways.list.each do|gateway|
|
|
435
|
+
x = gateway.host
|
|
436
|
+
x += ':'+gateway.port if gateway.port
|
|
437
|
+
lines.push(x)
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
lines.push(' ')
|
|
442
|
+
|
|
443
|
+
lines.each do |line|
|
|
444
|
+
event = {'msg' => line}
|
|
445
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
#@presences.each {|presence| lines.push(presence[0]+' - '+presence[1])}
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
help :cmd_presences, "List all defined presences"
|
|
452
|
+
def cmd_presences(arguments, target)
|
|
453
|
+
lines = ['Defined Presences:']
|
|
454
|
+
|
|
455
|
+
#~ @serverlist.servers.each do |server|
|
|
456
|
+
#~ network, presence = server.getnetworkpresencepair
|
|
457
|
+
#~ if server.connected
|
|
458
|
+
#~ lines.push(network+' - '+presence+' - Connected')
|
|
459
|
+
#~ else
|
|
460
|
+
#~ lines.push(network+' - '+presence)
|
|
461
|
+
#~ end
|
|
462
|
+
#~ end
|
|
463
|
+
|
|
464
|
+
@networks.list.each do |network|
|
|
465
|
+
network.presences.list.each do|presence|
|
|
466
|
+
lines.push(network.name+' - '+presence.name)
|
|
467
|
+
end
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
lines.push(' ')
|
|
471
|
+
|
|
472
|
+
lines.each do |line|
|
|
473
|
+
event = {'msg' => line}
|
|
474
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
help :cmd_channels, "List all defined channels"
|
|
481
|
+
def cmd_channels(arguments, target)
|
|
482
|
+
lines = ['Defined Channels:']
|
|
483
|
+
|
|
484
|
+
@buffers.values.select{|x| x.class == ChannelBuffer}.sort{|x, y| x.name<=>y.name}.each do |channel|
|
|
485
|
+
if channel.joined?
|
|
486
|
+
lines.push(channel.network.name+' - '+channel.presence+' - '+channel.name+' - Connected')
|
|
487
|
+
else
|
|
488
|
+
lines.push(channel.network.name+' - '+channel.presence+' - '+channel.name)
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
lines.push(' ')
|
|
493
|
+
|
|
494
|
+
lines.each do |line|
|
|
495
|
+
event = {'msg' => line}
|
|
496
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
497
|
+
end
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
# if $args['debug']
|
|
501
|
+
def cmd_reload(arguments, target)
|
|
502
|
+
if !arguments.include? '.'
|
|
503
|
+
arguments += '.rb'
|
|
504
|
+
end
|
|
505
|
+
begin
|
|
506
|
+
load "#{arguments}"
|
|
507
|
+
rescue LoadError
|
|
508
|
+
puts "failed to load #{arguments}"
|
|
509
|
+
rescue SyntaxError
|
|
510
|
+
puts "Failed to load #{arguments}, syntax error"
|
|
511
|
+
else
|
|
512
|
+
puts "reload of #{arguments} sucessful"
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
# end
|
|
516
|
+
|
|
517
|
+
help :cmd_load, "Specify a plugin to load. Usage: /load <name>"
|
|
518
|
+
def cmd_load(arguments, target)
|
|
519
|
+
unless arguments
|
|
520
|
+
throw_error('Specify a plugin to load.')
|
|
521
|
+
return
|
|
522
|
+
end
|
|
523
|
+
plugin_load(arguments)
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
help :cmd_unload, "Specify a plugin to unload. Usage: /unload <name>"
|
|
527
|
+
def cmd_unload(arguments, *args)
|
|
528
|
+
unless arguments
|
|
529
|
+
throw_error('Specify a plugin to unload.')
|
|
530
|
+
return
|
|
531
|
+
end
|
|
532
|
+
if plugin = Plugin[arguments]
|
|
533
|
+
Plugin.unregister(plugin)
|
|
534
|
+
else
|
|
535
|
+
throw_error('No plugin found called '+arguments)
|
|
536
|
+
end
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
help :cmd_pluginlist, "List all loaded plugins"
|
|
540
|
+
def cmd_pluginlist(arguments, target)
|
|
541
|
+
lines = ['Loaded Plugins:']
|
|
542
|
+
plugins = Plugin.list
|
|
543
|
+
plugins.each do |key, values|
|
|
544
|
+
# v.each do |key, values|
|
|
545
|
+
temp = values[:name]
|
|
546
|
+
# values.each do |value|
|
|
547
|
+
# #puts k.name, key, value
|
|
548
|
+
# temp += ' '+value[1].to_s+'#'+value[0]
|
|
549
|
+
# end
|
|
550
|
+
lines.push(temp)
|
|
551
|
+
# end
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
lines.push(' ')
|
|
555
|
+
|
|
556
|
+
lines.each do |line|
|
|
557
|
+
event = {'msg' => line}
|
|
558
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
559
|
+
end
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
help :cmd_alias, "Define an alias. Usage: /alias <aliasname> <aliascommand>"
|
|
563
|
+
def cmd_alias(arguments, target)
|
|
564
|
+
splitter = ' '
|
|
565
|
+
if arguments.include?(' /')
|
|
566
|
+
splitter = ' /'
|
|
567
|
+
end
|
|
568
|
+
original, cmdalias = arguments.split(splitter, 2).map{|e| e.strip}
|
|
569
|
+
|
|
570
|
+
if splitter == ' /'
|
|
571
|
+
cmdalias = '/'+cmdalias
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
puts 'aliased '+original+' to '+cmdalias
|
|
575
|
+
|
|
576
|
+
#puts original.class, cmdalias.class
|
|
577
|
+
|
|
578
|
+
@config['aliases'] ||= {}
|
|
579
|
+
@config['aliases'][original] = cmdalias
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
help :cmd_unalias, "Remove an alias. Usage: /unalias <aliasname>"
|
|
583
|
+
def cmd_unalias(arguments, target)
|
|
584
|
+
|
|
585
|
+
cmd, other = arguments.split(' ', 2)
|
|
586
|
+
|
|
587
|
+
cmd.strip!
|
|
588
|
+
|
|
589
|
+
@config['aliases'].delete(cmd)
|
|
590
|
+
|
|
591
|
+
puts 'unaliased '+cmd
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
help :cmd_aliases, "List all defined aliases"
|
|
595
|
+
def cmd_aliases(arguments, target)
|
|
596
|
+
lines = ['Aliases:']
|
|
597
|
+
|
|
598
|
+
@config['aliases'].each do |original, cmdalias|
|
|
599
|
+
# puts original.class, cmdalias.class
|
|
600
|
+
lines.push(original+' => '+cmdalias)
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
lines.push(' ')
|
|
604
|
+
|
|
605
|
+
lines.each do |line|
|
|
606
|
+
event = {'msg' => line}
|
|
607
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
608
|
+
end
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
help :cmd_version, "Print what version of ratchet you are currently using"
|
|
612
|
+
def cmd_version(arguments, target)
|
|
613
|
+
target.send_user_event({:msg => "Currently running Ratchet-#{$version}"}, EVENT_NOTICE)
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
help :cmd_help, "Get help on commands. Usage: /help [command]"
|
|
617
|
+
def cmd_help(arguments, target)
|
|
618
|
+
#puts 'help', self
|
|
619
|
+
#puts self.class.methods - self.class.superclass.methods
|
|
620
|
+
command_methods = command_list
|
|
621
|
+
if arguments
|
|
622
|
+
# command_methods = (self.methods).select{|method| method =~ /^cmd_/}
|
|
623
|
+
# command_methods = command_methods.select{|method| method[4..-1] == arguments}
|
|
624
|
+
command_methods = command_methods.detect{|method| method[1..-1] == arguments}
|
|
625
|
+
# command_methods ||= @config['aliases'].detect{|k,v| k == arguments}[0]
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
return unless command_methods
|
|
629
|
+
|
|
630
|
+
unless arguments
|
|
631
|
+
event = {'msg' => "Interactive help system"}
|
|
632
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
633
|
+
event = {'msg' => "<> denotes a required argument, [] denotes an optional one"}
|
|
634
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
635
|
+
event = {'msg' => ""}
|
|
636
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
637
|
+
end
|
|
638
|
+
|
|
639
|
+
command_methods.sort.each do |method|
|
|
640
|
+
# puts method, self.methods.include?('cmd_'+method[1..-1]), @config['aliases'][method[1..-1]]
|
|
641
|
+
if self.methods.include? 'cmd_'+method[1..-1]
|
|
642
|
+
if self.help('cmd_'+method[1..-1])
|
|
643
|
+
event = {'msg' => method+' : '+self.help('cmd_'+method[1..-1]).to_s}
|
|
644
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
645
|
+
else
|
|
646
|
+
event = {'msg' => method+" : Undocumented command"}
|
|
647
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
648
|
+
end
|
|
649
|
+
elsif al = @config['aliases'][method[1..-1]]
|
|
650
|
+
event = {'msg' => "#{method} : alias for #{al}"}
|
|
651
|
+
target.send_user_event(event, EVENT_NOTICE)
|
|
652
|
+
end
|
|
653
|
+
end
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
def command_list
|
|
657
|
+
a = (self.methods).select{|method| method =~ /^cmd_/}.map{|x| '/'+(x[4..-1])}
|
|
658
|
+
a += @config['aliases'].keys.map{|x| '/'+x}
|
|
659
|
+
#TODO - aliases too
|
|
660
|
+
a.sort
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
#sorta like method_missing
|
|
664
|
+
def command_missing(command, arguments, target)
|
|
665
|
+
throw_error("Unknown command /#{command}")
|
|
666
|
+
end
|
|
667
|
+
end
|
|
668
|
+
end
|