From 8c8d604d6eb4106851137c45d059dcd0dc7f16aa Mon Sep 17 00:00:00 2001 From: Th0masR0ss Date: Tue, 12 Nov 2013 20:22:32 -0500 Subject: [PATCH] Sneakily add myself to contributors list, start to add updating databases --- .idea/TriviaTime.iml | 16 ++++++++++++++++ __init__.py | 2 +- plugin.py | 36 ++++++++++++++++++++++++++++++++---- storage/samplequestions | 5 +---- 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 .idea/TriviaTime.iml diff --git a/.idea/TriviaTime.iml b/.idea/TriviaTime.iml new file mode 100644 index 0000000..cb7a849 --- /dev/null +++ b/.idea/TriviaTime.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/__init__.py b/__init__.py index 21665f9..d68a8cd 100644 --- a/__init__.py +++ b/__init__.py @@ -22,7 +22,7 @@ __author__ = supybot.Author('Tanner', 'tann', # This is a dictionary mapping supybot.Author instances to lists of # contributions. -__contributors__ = {'rootcoma'} +__contributors__ = {'rootcoma', 'Th0masR0ss;} # This is a url where the most recent plugin package can be downloaded. __url__ = 'https://github.com/tannn/TriviaTime/tree/master' diff --git a/plugin.py b/plugin.py index 3c38489..65e200d 100644 --- a/plugin.py +++ b/plugin.py @@ -65,9 +65,14 @@ class TriviaTime(callbacks.Plugin): self.storage.makeEditTable() #self.storage.insertUserLog('root', 1, 1, 10, 10, 30, 2013) #self.storage.insertUser('root', 1, 1) + self.storage.makeInfoTable() #filename = self.registryValue('quizfile') #self.addQuestionsFromFile(filename) + #triviainfo table check + if self.storage.isTriviaVersionSet(): + if self.storage.getVersion() != None & self.storage.getVersion() != self.currentVersion: + #HERE IS WHERE WE UPDATE THE DATABASE. def doPrivmsg(self, irc, msg): """ @@ -321,7 +326,7 @@ class TriviaTime(callbacks.Plugin): if len(info) < 3: irc.error("I couldn't find you in my database.") else: - infoText = ' %s\'s Stats: \x02Today:\x02 #%d %d (%d) \x02This Week:\x02 #%d %d (%d) \x02This Month:\x02 #%d %d (%d) \x02This Year:\x02 #%d %d (%d)' % (username, info[16], info[10], info[11], info[15], info[8], info[9], info[14], info[6], info[7], info[13], info[4], info[5]) + infoText = ' %s\'s Stats: \x02Today:\x02 #%d %d (%d) \x02This Week:\x02 #%d %d (%d) \x02This Month:\x02 #%d %d (%d) \x02This Year:\x02 #%d %d (%dhttps://github.com/tannn/TriviaTime/issues/63)' % (username, info[16], info[10], info[11], info[15], info[8], info[9], info[14], info[6], info[7], info[13], info[4], info[5]) irc.sendMsg(ircmsgs.privmsg(channel, infoText)) irc.noReply() me = wrap(me) @@ -1247,7 +1252,13 @@ class TriviaTime(callbacks.Plugin): self.conn = sqlite3.connect(loc, check_same_thread=False) # dont check threads # otherwise errors self.conn.text_factory = str - + def getVersion(self): + c = self.conn.cursor(); + try: + c.execute('''select version from triviainfo''') + return c.fetchone() + except: + pass def chunk(self, qs, rows=10000): """ Divides the data into 10000 rows each """ for i in xrange(0, len(qs), rows): @@ -2083,7 +2094,14 @@ class TriviaTime(callbacks.Plugin): pass self.conn.commit() c.close() - + def makeInfoTable(self): + c = self.conn.cursor() + try: + c.execute('''create table triviainfo ( + version integer + )''') + except: + pass def questionExists(self, question): c = self.conn.cursor() result = c.execute('select count(id) from triviaquestion where question=? or question_canonical=?', (question,question)) @@ -2452,6 +2470,16 @@ class TriviaTime(callbacks.Plugin): if rows > 0: return True return False - + def isTriviaVersionSet(self): + c = self.conn.cursor() + try: + c.execute('''select * from triviainfo''') + data = c.fetchall() + if len(data) == 0: + return False + return True + except: + pass + return False Class = TriviaTime # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/storage/samplequestions b/storage/samplequestions index 9add35a..36f1638 100644 --- a/storage/samplequestions +++ b/storage/samplequestions @@ -1,4 +1 @@ -foo*bar -Hello*world -Answer to everything*42 -Lorem*Ipsum +what is this?*sparta! \ No newline at end of file