7 def ctcp(network
, user
, msg
):
8 param_list
= msg
.split(' ')
9 param_list
[0] = param_list
[0].upper()
10 network
.raw('PRIVMSG %s :\x01%s\x01' % (user
,' '.join(param_list
)))
12 def ctcp_reply(network
, user
, msg
):
13 param_list
= msg
.split(' ')
14 param_list
[0] = param_list
[0].upper()
15 network
.raw('NOTICE %s :\x01%s\x01' % (user
,' '.join(param_list
)))
17 def emote(network
, user
, msg
):
18 network
.raw("PRIVMSG %s :\x01ACTION %s\x01" % (user
, msg
))
20 'OwnAction', network
=network
, window
=windows
.get_default(network
),
21 source
=network
.me
, target
=str(user
), text
=msg
25 if isinstance(e
.window
, windows
.ChannelWindow
) or isinstance(e
.window
, windows
.QueryWindow
):
26 #kludge around switches so we don't lose the -> in /me -> something
27 #emote(e.network, e.window.id, ' '.join(e.args))
28 command
, text
= e
.text
.split(" ",1)
29 emote(e
.network
, e
.window
.id, text
)
31 raise events
.CommandError("There's no one here to speak to.")
34 ctcp(e
.network
, e
.args
[0], ' '.join(e
.args
[1:]))
37 ctcp(e
.network
, e
.args
[0], 'PING %s' % time
.time())
39 def onCommandCtcpreply(e
):
40 ctcp_reply(e
.network
, e
.args
[0], ' '.join(e
.args
[1:]))
43 if not e
.done
and e
.msg
[1] in ('PRIVMSG', 'NOTICE') and \
44 e
.text
.startswith('\x01') and e
.text
.endswith('\x01'):
45 e_data
= events
.data(**e
.__dict
__)
46 e_data
.text
= e
.text
[1:-1]
47 tokens
= e_data
.text
.split(' ')
48 e_data
.name
= tokens
[0].upper()
49 e_data
.args
= tokens
[1:]
50 if e
.msg
[1] == 'PRIVMSG':
51 events
.trigger('Ctcp', e_data
)
53 events
.trigger('CtcpReply', e_data
)
56 def setupCtcpReply(e
):
59 elapsed_time
= "%0.2f seconds" % (time
.time() - float(e
.args
[0]))
61 e
.args
= [elapsed_time
]
67 if e
.name
== 'ACTION':
68 e_data
= events
.data(**e
.__dict
__)
69 e_data
.text
= ' '.join(e
.args
)
70 events
.trigger('Action', e_data
)
73 elif e
.name
== 'PING':
74 ctcp_reply(e
.network
, e
.source
, e
.text
)
76 elif e
.name
== 'VERSION':
77 ctcp_reply(e
.network
, e
.source
, 'VERSION %s - %s' % (urk
.long_version
, urk
.website
))
79 elif e
.name
== 'TIME':
80 ctcp_reply(e
.network
, e
.source
, 'TIME %s' % time
.asctime())