-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathircyborg.py
66 lines (49 loc) · 1.72 KB
/
ircyborg.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
from settings import NICK, IDENT, SERVER, REALNAME, CHANNEL
from googleSearch import googleSearch
from geoLocate import geoLocate
from imdb import imdbSearch
from weather import weatherLookup
import irc
# Event listeners
def handle_state(newstate):
if newstate == 4:
conn.send_string('JOIN {0}'.format(CHANNEL))
def handle_raw(line):
print line
def handle_parsed(prefix, command, params):
if command == 'PRIVMSG':
if(params[0] == CHANNEL
and params[1].startswith('!g')
and not params[1].startswith('!geo')):
searchTerm = params[1][3:]
conn.send_string(
'PRIVMSG {0} :'.format(CHANNEL) + googleSearch(searchTerm)
)
if params[0] == CHANNEL and params[1].startswith('!geo'):
searchTerm = params[1][5:]
conn.send_string(
'PRIVMSG {0} :'.format(CHANNEL) + geoLocate(searchTerm)
)
if params[0] == CHANNEL and params[1].startswith('!imdb'):
searchTerm = params[1][6:]
conn.send_string(
'PRIVMSG {0} :'.format(CHANNEL) + imdbSearch(searchTerm)
)
if params[0] == CHANNEL and params[1].startswith('!w'):
searchTerm = params[1][3:]
conn.send_string(
'PRIVMSG {0} :'.format(CHANNEL) + weatherLookup(searchTerm)
)
# Connection details
irc = irc.IRC_Object()
conn = irc.new_connection()
conn.nick = NICK
conn.ident = IDENT
conn.server = SERVER
conn.realname = REALNAME
# The event listeners
conn.events['state'].add_listener(handle_state)
conn.events['raw'].add_listener(handle_raw)
conn.events['parsed'].add_listener(handle_parsed)
while 1:
irc.main_loop()