-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.py
31 lines (29 loc) · 873 Bytes
/
messages.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
import sqlite3,random
import re
def get_greeting(conn):
cursor=conn.cursor()
cursor.execute('select greeting from greetings')
greet_list=cursor.fetchall()
number=len(greet_list)
conn.commit()
cursor.close()
return greet_list[random.randrange(0,number-1)][0]
def act_on_message(conn,settings,nick,text):
responces=[]
if nick==settings['nick']:
return responces
cursor=conn.cursor()
cursor.execute('select regexp,reaction from regexp')
data_list=cursor.fetchall()
for tt in data_list:
try:
regexp=tt[0]
pattern=re.compile(regexp)
if pattern.search(nick+':'+text) != None:
print tt[1]
responces.append(tt[1])
except:
print "Regexp %s failed on %s"%(tt[0],nick+':'+text)
conn.commit()
cursor.close()
return responces