forked from gentoomen/bhottu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ircbase.py
58 lines (51 loc) · 1.57 KB
/
ircbase.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
51
52
53
54
55
56
57
58
from api import *
_nick = None
_ident = None
_mode = None
_realname = None
_channels = None
_nickservPassword = None
_shouldJoin = None
def load(nick, ident, mode, realname, channels, nickservPassword):
global _nick, _ident, _mode, _realname, _channels, _nickservPassword
_nick = nick
_ident = ident
_mode = mode
_realname = realname
_channels = channels
_nickservPassword = nickservPassword
registerCommandHandler('439', _identify)
registerCommandHandler('376', _authorize)
registerCommandHandler('MODE', _checkAuthorize)
registerCommandHandler('PING', _pong)
def _identify():
sendCommand('USER %s %s * :%s' % (_ident, _mode, _realname))
sendCommand('NICK %s' % _nick)
def _authorize():
global _shouldJoin
if _nickservPassword == None:
_join()
return
log.info('Registering nick')
sendPrivmsg('nickserv', 'identify %s' % _nickservPassword)
_shouldJoin = True
def _checkAuthorize(arguments):
global _shouldJoin
if arguments[0] == _nick and _nickservPassword != None and _shouldJoin:
operation = None
for char in arguments[1]:
if char == '+':
operation = '+'
elif char == '-':
operation = '-'
elif char == 'r':
if operation == '+':
_join()
_shouldJoin = False
return
def _join():
for channel in _channels:
log.info('Joining channel %s' % channel)
sendJoin(channel)
def _pong(arguments):
sendCommand('PONG :%s' % arguments[0])