mirror of
https://github.com/house-of-vanity/conf_bot.git
synced 2025-07-06 22:34:07 +00:00
non-complete reset
This commit is contained in:
@ -2,7 +2,6 @@ BEGIN TRANSACTION;
|
||||
-- DROP TABLE IF EXISTS `word`;
|
||||
CREATE TABLE IF NOT EXISTS `word` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`is_russian` INTEGER NOT NULL,
|
||||
`word` TEXT UNIQUE
|
||||
);
|
||||
-- DROP TABLE IF EXISTS `user`;
|
||||
@ -14,6 +13,15 @@ CREATE TABLE IF NOT EXISTS `user` (
|
||||
`date` INTEGER NOT NULL,
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
-- DROP TABLE IF EXISTS `reset`;
|
||||
CREATE TABLE IF NOT EXISTS `reset` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`user_id` INTEGER,
|
||||
`conf_id` INTEGER,
|
||||
`date` INTEGER,
|
||||
`relation_id` INTEGER,
|
||||
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`)
|
||||
);
|
||||
-- DROP TABLE IF EXISTS `relations`;
|
||||
CREATE TABLE IF NOT EXISTS `relations` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
19
database.py
19
database.py
@ -79,13 +79,15 @@ class DataBase:
|
||||
LEFT JOIN word w ON w.id = r.word_id
|
||||
LEFT JOIN `user` u ON u.id = r.user_id
|
||||
WHERE u.id = '%s' AND
|
||||
r.conf_id = '%s'
|
||||
r.conf_id = '%s' AND
|
||||
r.id > (SELECT IFNULL(MAX(relation_id), 0) FROM reset WHERE user_id = '%s')
|
||||
GROUP BY w.word
|
||||
ORDER BY count DESC
|
||||
LIMIT %s
|
||||
""" % (
|
||||
user_id,
|
||||
conf_id,
|
||||
user_id,
|
||||
limit
|
||||
)
|
||||
result = self.execute(sql)
|
||||
@ -93,11 +95,12 @@ class DataBase:
|
||||
|
||||
def here(self, user_id, conf_id):
|
||||
sql= """
|
||||
select distinct(u.username) from relations r
|
||||
left join user u
|
||||
on u.id = r.user_id
|
||||
left join conf c on r.conf_id = c.id
|
||||
where c.id = '%s' and
|
||||
SELECT DISTINCT(u.username) FROM relations r
|
||||
LEFT JOIN user u
|
||||
ON u.id = r.user_id
|
||||
LEFT JOIN conf c
|
||||
ON r.conf_id = c.id
|
||||
WHERE c.id = '%s' and
|
||||
u.id != '%s'
|
||||
""" % (
|
||||
conf_id,
|
||||
@ -106,6 +109,10 @@ class DataBase:
|
||||
result = self.execute(sql)
|
||||
return(result)
|
||||
|
||||
# def reset(self, user_id, conf_id):
|
||||
# date = int(dt.datetime.now().strftime("%s"))
|
||||
# sql
|
||||
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
14
worker.py
14
worker.py
@ -32,6 +32,20 @@ class MessageWorker:
|
||||
message += '*%s*: %s\n' % (word[1], word[0])
|
||||
self.send(id=conf_id, msg=message)
|
||||
return True
|
||||
|
||||
if msg['message']['text'] == '/reset':
|
||||
conf_id = msg['message']['chat']['id']
|
||||
user_id = msg['message']['from']['id']
|
||||
chat_title = msg['message']['chat']['title']
|
||||
self.db.add_conf(conf_id, chat_title)
|
||||
|
||||
message = """Your stat has been resetted."""
|
||||
self.db.reset(
|
||||
conf_id=conf_id,
|
||||
user_id=user_id)
|
||||
|
||||
return True
|
||||
|
||||
if msg['message']['text'] == '@here':
|
||||
conf_id = msg['message']['chat']['id']
|
||||
user_id = msg['message']['from']['id']
|
||||
|
Reference in New Issue
Block a user