-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodel.py
More file actions
110 lines (77 loc) · 3.33 KB
/
model.py
File metadata and controls
110 lines (77 loc) · 3.33 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import sqlite3
import config
path = config.path + "triggerBot.db"
def addTrigger(message):
trigger = message.text.replace("/add_trigger ", "").lower()
dataBase = sqlite3.connect( path )
cursorDataBase = dataBase.cursor()
cursorDataBase.execute("SELECT text FROM triggers WHERE trigger = '%s' AND chatId = '%s'" % (trigger, message.chat.id))
row = cursorDataBase.fetchone()
if row is None:
update = False
else:
update = True
if message.reply_to_message.text is not None:
triggerText = str(message.reply_to_message.text)
triggerType = 'text'
elif message.reply_to_message.sticker is not None:
triggerText = str(message.reply_to_message.sticker.file_id)
triggerType = 'sticker'
elif message.reply_to_message.photo is not None:
triggerText = str(message.reply_to_message.photo[0].file_id)
triggerType = 'photo'
elif message.reply_to_message.video is not None:
triggerText = str(message.reply_to_message.video.file_id)
triggerType = 'video'
elif message.reply_to_message.voice is not None:
triggerText = str(message.reply_to_message.voice.file_id)
triggerType = 'voice'
elif message.reply_to_message.document is not None:
triggerText = str(message.reply_to_message.document.file_id)
triggerText = 'document'
elif message.reply_to_message.audio is not None:
triggerText = str(message.reply_to_message.audio.file_id)
triggerType = 'audio'
elif message.reply_to_message.video_note is not None:
triggerText = str(message.reply_to_message.video_note.file_id)
triggerType = 'video_note'
if update:
cursorDataBase.execute("UPDATE triggers SET type = '%s', text = '%s' WHERE chatId = %s AND trigger = '%s'" % (triggerType, triggerText, int(message.chat.id), trigger))
dataBase.commit()
else:
cursorDataBase.execute("INSERT INTO triggers (chatId, trigger, type, text) VALUES (%s, '%s', '%s', '%s')" % (int(message.chat.id), trigger, triggerType, triggerText))
dataBase.commit()
cursorDataBase.close()
dataBase.close()
def delTrigger(message):
trigger = message.text.replace("/del_trigger ", "").lower()
dataBase = sqlite3.connect( path )
cursorDataBase = dataBase.cursor()
cursorDataBase.execute("DELETE FROM triggers WHERE chatId = %s AND trigger = '%s'" % (message.chat.id, trigger))
dataBase.commit()
cursorDataBase.close()
dataBase.close()
def listTriggers(message):
dataBase = sqlite3.connect( path )
cursorDataBase = dataBase.cursor()
cursorDataBase.execute("SELECT trigger FROM triggers WHERE chatId = %s" % (message.chat.id))
row = cursorDataBase.fetchone()
index = 0
list = ''
while row is not None:
index += 1
list += str(index) + ") " + row[0] + "\n"
row = cursorDataBase.fetchone()
if list:
return list
else:
return "no triggers in this chat\n\n/add_trigger {trigger}"
def findTrigger(message):
dataBase = sqlite3.connect( path )
cursorDataBase = dataBase.cursor()
cursorDataBase.execute("SELECT type, text FROM triggers WHERE chatId = %s AND trigger = '%s'" % (message.chat.id, message.text.lower() ) )
row = cursorDataBase.fetchone()
if row is not None:
return row
else:
return None