-
+ 13BDA7A95EDFE0BF6BDBC56629A598B7D1AFA21AA96A49396CE49BDDB4DC10E5017BB78A098C7873950465044030D75440C476D5C1A14F996C34FB49721DE26B
postgres_interfacing.py
(0 . 0)(1 . 45)
220 import select
221 import psycopg2
222 import psycopg2.extensions
223 from knobs import config
224
225 class postgres_interfacing():
226
227 def __init__(self):
228 self.connection_string = config.postgres['connection_string']
229 self.postgres_channel = config.postgres['channel']
230 self.postgres_listen_string = "LISTEN %s;" % self.postgres_channel
231 self.bot_command_prefix = config.bot['bot_command_prefix']
232 self.bot_name = config.bot['bot_name']
233 self.route_all_notifications = config.route_all_notifications
234 self.ignore_list = config.ignore_list
235
236 def send_to_outbox(self, target, payload):
237 #Insert a target and message into the 'outbox' table on local postgres server
238 conn = psycopg2.connect(self.connection_string)
239 cur = conn.cursor()
240 cur.execute("INSERT INTO outbox(target, message) VALUES(%s,%s)", (target, payload))
241 conn.commit()
242 cur.close()
243 conn.close()
244
245 def irc_reply(self, target, source, payload):
246 if source != self.bot_name:
247 #make sure bot doesn't talk to itself
248 if target == self.bot_name:
249 #is the target this bot
250 self.send_to_outbox(source, payload)
251 elif target[:1] == '#':
252 #is the target a channel
253 self.send_to_outbox(target, payload)
254
255 def fetch_irc_message(self, log_id):
256 #Fetch the irc message in the 'log' table based off of the log id
257 conn = psycopg2.connect(self.connection_string)
258 cur = conn.cursor()
259 cur.execute("SELECT target, source, message FROM log WHERE id = %s;", (log_id,))
260 row = cur.fetchone()
261 target, source, message = row[0], row[1], row[2]
262 return target, source, message
263 cur.close()
264 conn.close()