From 67d6f47bc34d46f1be00007866b505ceca3006f9 Mon Sep 17 00:00:00 2001 From: Alexandr Godless Date: Tue, 20 Feb 2018 18:05:49 +0300 Subject: [PATCH] Reset feature --- .gitignore | 1 + database.py | 19 +++++++++++++++---- worker.py | 1 - 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b0d1d33..24d1d5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ assets/cert* **/settings.ini main.db +main.db-journal settings.ini \ No newline at end of file diff --git a/database.py b/database.py index f13475c..f87b1ee 100755 --- a/database.py +++ b/database.py @@ -80,7 +80,9 @@ class DataBase: LEFT JOIN `user` u ON u.id = r.user_id WHERE u.id = '%s' AND r.conf_id = '%s' AND - r.id > (SELECT IFNULL(MAX(relation_id), 0) FROM reset WHERE user_id = '%s') + r.id > ( + SELECT IFNULL(MAX(relation_id), 0) FROM reset WHERE user_id = '%s' AND conf_id = '%s' + ) GROUP BY w.word ORDER BY count DESC LIMIT %s @@ -109,9 +111,18 @@ class DataBase: result = self.execute(sql) return(result) -# def reset(self, user_id, conf_id): -# date = int(dt.datetime.now().strftime("%s")) -# sql + def reset(self, user_id, conf_id): + date = int(dt.datetime.now().strftime("%s")) + sql = """ + INSERT OR IGNORE INTO reset (user_id, conf_id, date, relation_id) + VALUES ('%s', '%s', '%s', (SELECT MAX(rowid) FROM relations)); + """ % ( + user_id, + conf_id, + date + ) + result = self.execute(sql) + return(result) def close(self): diff --git a/worker.py b/worker.py index 1d95f64..df58202 100755 --- a/worker.py +++ b/worker.py @@ -43,7 +43,6 @@ class MessageWorker: self.db.reset( conf_id=conf_id, user_id=user_id) - return True if msg['message']['text'] == '@here':