DB tidyup.
authorCMDR furrycat <elite@furrycat.net>
Mon, 3 Oct 2016 21:09:42 +0000 (22:09 +0100)
committerCMDR furrycat <elite@furrycat.net>
Mon, 3 Oct 2016 21:09:42 +0000 (22:09 +0100)
db.py

diff --git a/db.py b/db.py
index b07c62f..7796a0d 100644 (file)
--- a/db.py
+++ b/db.py
@@ -1,6 +1,7 @@
 import discord
 import logging
 import sqlite3
+import time
 import uuid
 
 log = logging.getLogger('db')
@@ -12,9 +13,12 @@ class DBConnection(object):
     self.open_db(filename)
     self.create_tables()
 
-  def uuid():
+  def uuid(self):
     return str(uuid.uuid4())
 
+  def now(self):
+    return int(time.time())
+
   def open_db(self, filename):
     self.dbh = sqlite3.connect(filename)
     self.dbh.row_factory = sqlite3.Row
@@ -33,8 +37,7 @@ class DBConnection(object):
     return cursor
 
   def get_state(self, client):
-    cursor = self.dbh.cursor()
-    self.query('select avatar, idle, last_spoke from state where bot_id=?', [client.user.id])
+    cursor = self.query('select avatar, idle, last_spoke from state where bot_id=?', [client.user.id])
     row = cursor.fetchone()
     if row is None:
       return None