-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
39 lines (36 loc) · 1.28 KB
/
Copy pathdb.py
File metadata and controls
39 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sqlite3
import time
def log_chat_into_database(bot, update):
chat_id = update.message.chat.id
ts = time.time()
conn = sqlite3.connect('log.db')
cursor = conn.execute(
'SELECT lastusage FROM chats WHERE chatid = ?', (chat_id, ))
data = cursor.fetchone()
if data is None:
print("The bot now is used in a new chat! (chatid = {})".format(chat_id))
conn.execute(
'INSERT INTO chats (chatid, lastusage) VALUES (?, ?)', (chat_id, ts))
conn.commit()
else:
conn.execute(
'UPDATE chats set lastusage = ? where chatid = ?', (ts, chat_id))
conn.commit()
conn.close()
count_interactions()
def log_sticker_into_database(file_id, chat_id, kept):
conn = sqlite3.connect('log.db')
ts = time.time()
conn.execute(
'INSERT INTO stickers (chatid, fileid, kept, time) VALUES (?, ?, ?, ?)', (file_id, chat_id, kept, ts))
conn.commit()
def count_interactions():
try:
counter = 0
with open('interactions.txt', 'r') as f:
counter = int(f.readline().strip())
counter += 1
with open('interactions.txt', 'w') as f:
f.write(str(counter))
except Exception as err:
print("Error while writing to file: {}".format(err))