-
Notifications
You must be signed in to change notification settings - Fork 0
/
speak_bot_ai.py
54 lines (38 loc) · 1.36 KB
/
speak_bot_ai.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
from bot import Bot
import re
import time
import ConfigParser
import sqlite3 as lite
import sys
class SpeakBotAI(Bot):
def __init__(self):
config = ConfigParser.RawConfigParser()
config.read('/opt/python/speaking_bot/speak_bot.cfg')
host = config.get('Bot','host')
channel = config.get('Bot','channel')
password = config.get('Bot','password')
nicks = config.get('Bot','nicks')
hostname = config.get('Bot','hostname')
debug = config.getboolean('Bot','debug')
log = config.getboolean('Bot','log')
self.con = lite.connect('/tmp/speakbot.db')
cur = self.con.cursor()
cur.execute("create TABLE if not exists talk ( id INTEGER PRIMARY KEY AUTOINCREMENT, handle TEXT, channel TEXT , message TEXT)")
self.con.commit()
self.logged_in = False
super(SpeakBotAI,self).__init__(host,channel,password,nicks,hostname,debug,log)
def log_connectivity(self,text):
pass
def archive_message(self,text,timestamp):
pass
def custom_ai(self,text,timestamp):
parsed_msg = self.parsemsg(text)
if parsed_msg is not None:
if text.find('SpeakBot @ ' + self.channel) != -1:
self.logged_in = True
if self.logged_in:
cur = self.con.cursor()
cur.execute('INSERT INTO talk(handle,channel,message) values (?,?,?)',(parsed_msg['handle'],parsed_msg['channel'],parsed_msg['text']))
self.con.commit()
#bot = SpeakBotAI()
#bot.run()