-
Notifications
You must be signed in to change notification settings - Fork 0
/
connversion.py
50 lines (40 loc) · 1.47 KB
/
connversion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# connversion.py: version users on connect
from pylinkirc import utils, world, conf
from pylinkirc.log import log
import time
desc = "CTCP bot, versions connecting users."
ctcp = utils.registerService("ctcp", nick="Aurora", ident="ctcp", desc=desc)
reply = ctcp.reply
error = ctcp.error
def hook_connversion(irc, source, command, args):
oursids = irc.serverdata.get('sids', [])
nickuid = source
nicksid = irc.getServer(nickuid)
nickts = int(irc.users[nickuid].ts)
nowts = int(time.time())
result = args['text']
result = result.split()
result = result[1:]
result = (" ").join(result)
result = result.strip('\x01')
if nowts <= nickts + 15:
if nicksid in oursids:
myuid = ctcp.uids.get(irc.name)
if args['text'].startswith('\x01') and args['text'].endswith('\x01'):
irc.proto.message(myuid, '#debug', "Received VERSION reply from %s, using: %s" % (irc.getFriendlyName(source), result))
utils.add_hook(hook_connversion, 'NOTICE')
def hook_uid(irc, source, command, args):
try:
myuid = ctcp.uids.get(irc.name)
oursids = irc.serverdata.get('sids', [])
nick = args['nick']
nickuid = args['uid']
nowts = int(time.time())
theirts = int(args['ts'])
if source in oursids:
irc.proto.message(myuid, nickuid, "\x01VERSION\x01")
except LookupError:
pass
utils.add_hook(hook_uid, 'UID')
def die(irc):
utils.unregisterService('ctcp')