-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtele.py
229 lines (185 loc) · 8.25 KB
/
tele.py
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
221
222
223
224
225
226
227
228
import os
import telebot
import random
import consts
import urllib
import shelve
from urllib.request import Request
from telebot import types
from shelvetry import getanswer, incscore, decscore, getscore, getdif
geoanswer = shelve.open("geoanswer")
bot = telebot.TeleBot(consts.bottoken)
bot.send_message(120363877, "Начинай")
markupstart = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
@bot.message_handler(commands=['start'])
def starting(message):
markupstart.row("/game", "/trigonometry")
markupstart.row("/logarithm", "/derivativetable")
markupstart.row("/integral", "/randombook")
markupstart.row("/randomwiki", "/primetheory")
markupstart.row("/polynomialtheory", "/geogame")
bot.send_message(message.chat.id, consts.startstr, reply_markup=markupstart)
@bot.message_handler(commands=['game'])
def game_com(message):
from shelvetry import setgame
bot.send_message(message.chat.id, 'Welcome to the victorina.' )
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
markup.row("/difficult1")
markup.row("/difficult2")
markup.row("/difficult3")
keyboard_hider = types.ReplyKeyboardRemove()
bot.send_message(message.chat.id, consts.gamestr, reply_markup=markup)
setgame(message.chat.id)
@bot.message_handler(commands=['quit'])
def quit_com(message):
from shelvetry import endgame
bot.send_message(message.chat.id, 'Goodbye!')
endgame(message.chat.id)
bot.send_message(message.chat.id, consts.quitstr, reply_markup=markupstart)
@bot.message_handler(commands=['quitgeo'])
def quit_geo(message):
del geoanswer[str(message.chat.id)]
bot.send_message(message.chat.id, 'Goodbye!')
bot.send_message(message.chat.id, consts.quitstr, reply_markup=markupstart)
@bot.message_handler(commands=['trigonometry'])
def trig_theory(message):
directory = "D:/Users/Opsymonroe/Images/botphoto"
img = open(directory + '/' + 'trigonom.jpg', 'rb')
bot.send_chat_action(message.from_user.id, 'upload_photo')
bot.send_photo(message.from_user.id, img)
bot.send_message(message.from_user.id, consts.wikitrig)
@bot.message_handler(commands=['logarithm'])
def log_theory(message):
directory = "D:/Users/Opsymonroe/Images/botphoto"
img = open(directory + '/' + 'logarifm.jpg', 'rb')
bot.send_chat_action(message.from_user.id, 'upload_photo')
bot.send_photo(message.from_user.id, img)
bot.send_message(message.chat.id, consts.wikilog)
@bot.message_handler(commands=['derivativetable'])
def der_theory(message):
directory = "D:/Users/Opsymonroe/Images/botphoto"
img = open(directory + '/' + 'proizv.png', 'rb')
bot.send_chat_action(message.chat.id, 'upload_photo')
bot.send_photo(message.chat.id, img)
bot.send_message(message.chat.id, consts.wikider)
bot.send_message(message.chat.id, consts.wikidertable)
@bot.message_handler(commands=['integral'])
def int_theory(message):
directory = "D:/Users/Opsymonroe/Images/botphoto"
img = open(directory + '/' + 'pervoobr.jpg', 'rb')
bot.send_chat_action(message.chat.id, 'upload_photo')
bot.send_photo(message.chat.id, img)
bot.send_message(message.chat.id, consts.wikiint)
bot.send_message(message.chat.id, consts.wikiinttable)
@bot.message_handler(commands=['primetheory'])
def prime_theory(message):
bot.send_message(message.chat.id, consts.wikiprime)
@bot.message_handler(commands=['polynomialtheory'])
def pol_theory(message):
bot.send_message(message.chat.id, consts.wikipoly)
bot.send_message(message.chat.id, consts.wikiquad)
@bot.message_handler(commands=['randombook'])
def rand_book(message):
directory = "D:/Users/Opsymonroe/Documents/botdocs"
allbooks = os.listdir(directory)
randbook = random.choice(allbooks)
doc = open(directory + '/' + randbook, 'rb')
bot.send_chat_action(message.chat.id, 'upload_photo')
bot.send_document(message.chat.id, doc)
@bot.message_handler(commands=['randomwiki'])
def rand_wiki(message):
req = Request("https://en.wikipedia.org/wiki/Special:Random", headers={'User-Agent': 'Mozilla/5.0'})
webpage = urllib.request.urlopen(req)
wiki = webpage.geturl()
bot.send_message(message.chat.id, wiki)
from shelvetry import setdif
@bot.message_handler(commands=['difficult1'])
def chosedif(message):
setdif(message.chat.id, message.text[-1])
sendingtas(message.chat.id, message.text[-1])
@bot.message_handler(commands=['difficult2'])
def chosedif(message):
setdif(message.chat.id, message.text[-1])
sendingtas(message.chat.id, message.text[-1])
@bot.message_handler(commands=['difficult3'])
def chosedif(message):
setdif(message.chat.id, message.text[-1])
sendingtas(message.chat.id, message.text[-1])
@bot.message_handler(commands=['geogame'])
def geogame(message):
bot.send_message(message.chat.id, consts.geostart)
geoanswer[str(message.chat.id)] = [0, 0]
startgeo(message.chat.id)
@bot.message_handler(func=lambda message: True, content_types=['location'])
def location(message):
from distance import distance, score
geobase = shelve.open("D:/Users/Opsymonroe/Documents/botgeobase/geobase")
mas = str(message.location).split(',')
lat2 = mas[1][12: len(mas[1])-1]
lon2 = mas[0][13: len(mas[1])]
list = geoanswer[str(message.chat.id)]
lat1 = geobase[geoanswer[str(message.chat.id)][0]][0]
lon1 = geobase[geoanswer[str(message.chat.id)][0]][1]
dist = distance(lat1, lon1, lat2, lon2)
score1 = score(dist)
list = geoanswer[str(message.chat.id)]
score1 += float(list[1])
list[1] = str(score1)
geoanswer[str(message.chat.id)] = list
bot.send_message(message.chat.id, message.from_user.first_name + ", Your guess was " + str(dist) + " km from correct location, and your score now is "
+ str(geoanswer[str(message.chat.id)][1]))
geobase.close()
startgeo(message.chat.id)
def startgeo(id):
geobase = shelve.open("D:/Users/Opsymonroe/Documents/botgeobase/geobase")
keys = list(geobase.keys())
lockey = random.choice(keys)
list1 = geoanswer[str(id)]
list1[0] = lockey
geoanswer[str(id)] = list1
geodir = "D:/Users/Opsymonroe/Images/botgeo/"
img = open(geodir + lockey + '.jpg', 'rb')
bot.send_chat_action(id, 'upload_photo')
bot.send_photo(id, img)
print(str(geobase[lockey]))
geobase.close()
def sendingtas(id, diff):
from quiz import count, generate
from prime import isprime, inventing
from polynom import creating
from shelvetry import setans
from radius import deciding
keyboard_hider = types.ReplyKeyboardRemove()
mode = random.randint(0, 10)
mode = mode % 4
if (mode == 0):
s = generate(id, diff)
bot.send_message(id, s, reply_markup=keyboard_hider)
if ( mode == 1):
s = inventing(id, diff)
bot.send_message(id, 'Is {} prime? True/False'.format(s), reply_markup=keyboard_hider)
if(mode == 2):
s = creating(id, diff)
bot.send_message(id, 'Send multiplication of the roots of {}'.format(s), reply_markup=keyboard_hider)
if ( mode == 3):
s = deciding(id, diff)
bot.send_message(id, s, reply_markup=keyboard_hider)
"""Чел, просто расслабься, будь что будет. Тебе некуда торопиться, у тебя все хорошо.
Просто сделай отправку всех сообщений отдельно, а чтение отдельно, тогда все будет хорошо."""
@bot.message_handler(func=lambda message: True, content_types=['text'])
def game(message):
print(message.chat.id)
print(message.from_user.id)
ans = getanswer(message.chat.id)
if not ans:
bot.send_message(message.chat.id, 'Type /game to start')
return
if(str(ans).lower() == message.text.lower()):
incscore(message.chat.id)
bot.send_message(message.chat.id, message.from_user.first_name + ', Great! Your score now is ' + str(getscore(message.chat.id)) + '.')
else:
decscore(message.chat.id)
bot.send_message(message.chat.id, message.from_user.first_name + ', Bad! Right answer is ' + str(ans) + ', and your score now is' + str(getscore(message.chat.id)) + '.')
sendingtas(message.chat.id, getdif(message.chat.id))
if __name__ == '__main__':
bot.polling(none_stop=True)