-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
220 lines (202 loc) · 9.32 KB
/
run.py
File metadata and controls
220 lines (202 loc) · 9.32 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import telebot
import sqlite3
from random import randint
from telebot import types
import config
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def start_command(message):
if ((message.chat.type == 'group' or message.chat.type == 'supergroup') and message.text == '/start@EGEStress_bot') or message.chat.type == 'private':
CurrentWord = DBChangeWord(message.chat.id)
bot.send_message(message.chat.id, 'Привет, я стрессбот! Давай так: я тебе буду отправлять слова, а ты мне их будешь возвращать, но с одним ударным звуком. \r\nНапример: \r\n-звонить\r\n-звонИть \r\nЕсли я в группе, то, чтобы я мог проверить ваш ответ, пишите его при пересылке моего сообщения с помощью "Reply"')
# bot.send_message(message.chat.id, config.listof_testwords[CurrentWord])
mmessage = WordSplit(CurrentWord, message.chat.id)
DBSetLastMID(message.chat.id, mmessage.message_id, mmessage.text)
@bot.message_handler(commands=['cword'])
def cword_command(message):
if ((message.chat.type == 'group' or message.chat.type == 'supergroup') and message.text == '/cword@EGEStress_bot') or message.chat.type == 'private':
CurrentWord = DBWhichWord(message.chat.id)
mmessage = WordSplit(CurrentWord, message.chat.id)
DBSetLastMID(message.chat.id, mmessage.message_id, mmessage.text)
@bot.message_handler(commands=['stats'])
def stats_command(message):
if ((message.chat.type == 'group' or message.chat.type == 'supergroup') and message.text == '/stats@EGEStress_bot') or message.chat.type == 'private':
bot.send_message(message.chat.id, DBCounter(message.chat.id))
@bot.message_handler(content_types=['text'])
def WordCheck(message):
usedword = message.text.split(' ')[0]
correct = DBWordCheck(message.chat.id, usedword)
if correct == 1:
bot.send_message(message.chat.id, 'Верно!')
DBAddToCounter(message.chat.id, True)
elif correct == 2:
DBAddUser(message.chat.id)
else:
bot.send_message(message.chat.id, 'Нет! Надо вот так: ' + config.listof_correctwords[correct])
DBAddToCounter(message.chat.id, False)
CurrentWord = DBChangeWord(message.chat.id)
mmessage = WordSplit(CurrentWord, message.chat.id)
bot.edit_message_text(chat_id=message.chat.id, message_id=DBLastMID(message.chat.id), text = str(DBLastMES(message.chat.id)) + ' | Вы ввели: ' + usedword)
DBSetLastMID(message.chat.id, mmessage.message_id, mmessage.text)
@bot.callback_query_handler(func=lambda call:True)
def ButtonWordCheck(call):
if call.message.message_id == DBLastMID(call.message.chat.id):
correct = DBWordCheck(call.message.chat.id, call.data)
if correct == 1:
bot.send_message(call.message.chat.id, 'Верно!')
DBAddToCounter(call.message.chat.id, True)
elif correct == 2:
DBAddUser(call.message.chat.id)
return
else:
bot.send_message(call.message.chat.id, 'Нет! Надо вот так: ' + config.listof_correctwords[correct])
DBAddToCounter(call.message.chat.id, False)
CurrentWord = DBChangeWord(call.message.chat.id)
mmessage = WordSplit(CurrentWord, call.message.chat.id)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=DBLastMID(call.message.chat.id), text=DBLastMES(call.message.chat.id) + ' | Вы ввели: ' + call.data)
DBSetLastMID(call.message.chat.id, mmessage.message_id, mmessage.text)
def DBAddUser(user):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
word = randint(0, 454)
cursor.execute('insert into hooy(User, CurrentWord, Wins, Loses) values(?,?,?,?)', (user, word, 0, 0))
connection.commit()
connection.close()
return word
def DBChangeWord(user):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('SELECT CurrentWord FROM hooy WHERE User = ?', (user,))
a = cursor.fetchone()
if a is None:
word = DBAddUser(user)
connection.commit()
connection.close()
return word
else:
word = randint(0, 454)
cursor.execute('UPDATE hooy SET CurrentWord = ? WHERE User = ?', (word, user))
connection.commit()
connection.close()
return word
def DBWordCheck(user, word):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('SELECT CurrentWord FROM hooy WHERE User = ?', (user,))
a = cursor.fetchone()
if a is None:
return 2
elif word == config.listof_correctwords[a[0]]:
return 1
else:
return a[0]
connection.commit()
connection.close()
def DBWhichWord(user):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('SELECT CurrentWord FROM hooy WHERE User = ?', (user,))
a = cursor.fetchone()
if a is None:
a = DBAddUser(user)
else:
a = a[0]
connection.commit()
connection.close()
return a
def DBAddToCounter(user, wol):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
if wol:
cursor.execute('SELECT Wins FROM hooy WHERE User = ?', (user,))
a = int(cursor.fetchone()[0]) + 1
cursor.execute('UPDATE hooy SET Wins = ? WHERE User = ?', (a, user))
else:
cursor.execute('SELECT Loses FROM hooy WHERE User = ?', (user,))
a = int(cursor.fetchone()[0]) + 1
cursor.execute('UPDATE hooy SET Loses = ? WHERE User = ?', (a, user))
connection.commit()
connection.close()
def DBCounter(user):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('SELECT Wins FROM hooy WHERE User = ?', (user,))
wins = cursor.fetchone()[0]
cursor.execute('SELECT Loses FROM hooy WHERE User = ?', (user,))
loses = cursor.fetchone()[0]
connection.commit()
connection.close()
a = 'Wins/Loses:\r\n' + str(wins) + '/' + str(loses)
return a
def DBLastMID(user):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('SELECT LastMID FROM hooy WHERE User = ?', (user,))
lmid = cursor.fetchone()[0]
connection.commit()
connection.close()
return lmid
def DBLastMES(user):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('SELECT LastMES FROM hooy WHERE User = ?', (user,))
lmes = cursor.fetchone()[0]
connection.commit()
connection.close()
return lmes
def DBSetLastMID(user, mid, text):
connection = sqlite3.connect('currentwords.db')
cursor = connection.cursor()
cursor.execute('UPDATE hooy SET LastMID = ? WHERE User = ?', (mid, user))
cursor.execute('UPDATE hooy SET LastMES = ? WHERE User = ?', (text, user))
connection.commit()
connection.close()
def WordSplit(word, chatid):
a = 0
buttonlist = []
cword = config.listof_testwords[word]
keyboard = types.InlineKeyboardMarkup(row_width=3)
for i in range(len(cword)):
if cword[i] in config.galphabet:
if i+1 < len(cword):
buttonlist.append(cword[:i] + cword[i].upper() + cword[i+1:])
else:
buttonlist.append(cword[:i] + cword[i].upper())
for i in buttonlist:
if a == 0:
callback_button0 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 1:
callback_button1 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 2:
callback_button2 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 3:
callback_button3 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 4:
callback_button4 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 5:
callback_button5 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 6:
callback_button6 = types.InlineKeyboardButton(text=i, callback_data=i)
elif a == 7:
callback_button7 = types.InlineKeyboardButton(text=i, callback_data=i)
a += 1
a -= 1
if a == 0:
keyboard.add(callback_button0)
elif a == 1:
keyboard.add(callback_button0, callback_button1)
elif a == 2:
keyboard.add(callback_button0, callback_button1, callback_button2)
elif a == 3:
keyboard.add(callback_button0, callback_button1, callback_button2, callback_button3)
elif a == 4:
keyboard.add(callback_button0, callback_button1, callback_button2, callback_button3, callback_button4)
elif a == 5:
keyboard.add(callback_button0, callback_button1, callback_button2, callback_button3, callback_button4, callback_button5)
elif a == 6:
keyboard.add(callback_button0, callback_button1, callback_button2, callback_button3, callback_button4, callback_button5, callback_button6)
elif a == 7:
keyboard.add(callback_button0, callback_button1, callback_button2, callback_button3, callback_button4, callback_button5, callback_button6, callback_button7)
mmessage = bot.send_message(chatid, cword, reply_markup=keyboard)
return mmessage
bot.polling(none_stop=True)