-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
executable file
·110 lines (89 loc) · 3.17 KB
/
bot.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python2.7
import sys
import socket
import string
import utils
import settings
import privmsg
from handlers import *
def connect(HOST, PORT, NICK, IDENT, REALNAME, PASS, CHANNEL):
conn.connect((HOST, PORT))
conn.send('NICK '+NICK+'\r\n')
conn.send('USER '+IDENT+' '+HOST+' * :'+REALNAME+'\r\n')
initialPing() # Wait for initial ping
conn.send('PRIVMSG NickServ IDENTIFY '+PASS+'\r\n')
conn.send('JOIN '+CHANNEL+'\r\n')
conn.send('PRIVMSG '+CHANNEL+' :Quack!\r\n')
def sendPing(ping):
conn.send('PONG '+ping+'\r\n')
print 'PONG'
def initialPing():
for line in conn.makefile('r'):
print line
if line.split()[0] == 'PING':
sendPing(line.split()[1])
print 'Initial PONG sent'
break
modes = { 'owner': '+q', 'o': '+q',
'deowner': '-q', 'do': '-q',
'protected': '+p', 'protect': '+p', 'p': '+p',
'deprotected': '-p', 'deprotect': '-p', 'dp': '-p',
'operator': '+o', 'op': '+o',
'deoperator': '-o', 'deop': '-o', 'dop': '-o',
'halfop': '+ho', 'hop': '+ho', 'ho': '+ho',
'dehalfop': '-ho', 'dho': '-ho',
'voice': '+v', 'v': '+v',
'devoice': '-v', 'dv': '-v',
'ban': '+b', 'b': '+b',
'unban': '-b', 'b': '-b',
}
def changeMode(conn, msg):
if utils.isadmin(conn, msg):
cmd = msg.text.split()[0][1:]
if len(msg.text.split()) > 1:
wie = msg.text.split()[1]
else:
wie = msg.user
conn.send('MODE %s %s %s\r\n' % (msg.channel, modes[cmd], wie))
else:
conn.send('PRIVMSG %s :Je moet een operator zijn om dit commando te kunnen uitvoeren.\r\n' % msg.user)
actions = {'kick': kick.kick,
'k': kick.kick,
'topic': topic.topic,
't': topic.topic,
'addquote': quote.addquote,
'quote': quote.quote,
'delquote': quote.delquote,
'tell': tell.tell,
'assign': definitions.assign,
'reassign': definitions.reassign,
'unassign': definitions.unassign,
'list': definitions.list,
'dt': dt.dt,
'dtlist': dt.list,
'oa': onzinalarm.alarm,
'help': help.help
}
def parseMessage(data):
msg = privmsg.PrivMSG(data)
tell.active(conn, msg)
if "Quack" in msg.text:
conn.send('PRIVMSG %s :Quack, %s!\r\n' % (msg.channel, msg.user))
if msg.char == '!':
if msg.cmd[0] in modes:
changeMode(conn, msg)
elif msg.cmd[0] in actions:
actions[msg.cmd[0]](conn, msg)
elif msg.char == '?':
definitions.explain(conn, msg)
def listen(channel, conn):
for line in conn.makefile('r'):
if len(line) > 0:
print line
if line.split()[0] == 'PING':
sendPing(line.split()[1])
if "PRIVMSG " + channel in line:
parseMessage(line)
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect(settings.irc_HOST, settings.irc_PORT, settings.irc_NICK, settings.irc_IDENT, settings.irc_REALNAME, settings.irc_PASS, settings.irc_CHANNEL)
listen(settings.irc_CHANNEL, conn)