-
Notifications
You must be signed in to change notification settings - Fork 10
/
Bot.py
335 lines (273 loc) · 10.1 KB
/
Bot.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import telebot
import datetime
import time
### HELP TEXT ------------------------------------------------------------------------|
'''
User Available Commands:
1. /poll
2. /stats
3. /start
4. /help
5. /groups
Developer Commands: #NOTE: ONLY @Parvat_R and @Rohithaditya are allowed for these comands:
1. /showIds
2. /botlogs
'''
### MAIN VARS ------------------------------------------------------------------------|
'''
THESE ARE THE IMPORTANT VARS FOR POLL BOT
'''
BOT_TOKEN = '8s858s85s:4g44g4646g464g4g448' # YOUR BOT TOKEN HERE GET FROM @BotFather
API_HASH = '85df55s5s5s55s55a4' # YOUR API HASH GET FROM my.telegram.org
API_ID = '1234567' # YOUR API ID GET FROM my.telegram.org
CHAT_ID = '-1001'# YOUR PRIVATE GROUP TO VIEW LOGS OR ERROR
USERNAME = 'Rohithaditya' # YOUR USERNAME THIS IS MANDTORY
### ABOVE MAIN VARS -------------------------------------------------------------------|
bot = telebot.TeleBot(token=BOT_TOKEN)
@bot.message_handler(commands=['showIds'])
def showIds(message):
try:
if message.from_user.username in ['Parvat_R', 'Rohithaditya', USERNAME]:
file = open('joined_groups.txt', 'r ')
bot.send_document(message.chat.id, file)
file.close()
except Exception as error:
bot.send_message(CHAT_ID, str(error))
@bot.message_handler(commands=['stats', 'groups'])
def stats(message):
try:
if message.from_user.username in['Parvat_R','Rohithaditya', USERNAME]:
print('Sending Stats To Owner')
with open('joined_groups.txt', 'r') as file:
group_ids = []
for line in file.readlines():
for group_id in line.split(' '):
group_ids.append(group_id)
no_of_polls = len(group_ids)
no_of_groups = len(list(set(group_ids)))
group_ids.clear()
bot.reply_to(message, f'Number of polls Maded: {no_of_polls}\nNo of groups bot has been added: {no_of_groups}')
file.close()
else:
bot.reply_to(message, f'Sorry {message.from_user.username}! You Are Not Allowed To Use This Command,')
except Exception as error:
bot.send_message(CHAT_ID, f'Hi Devs!!\nHandle This Error plox\n{error}')
try:
group_ids.clear()
except:
pass
bot.reply_to(message, f'An error occurred!\nError: {error}')
bot.send_message(CHAT_ID, f'An error occurred!\nError: {error}')
bot.send_document(CHAT_ID, '{message}')
@bot.message_handler(commands=['botlogs'])
def ViewTheLogsFile(message):
try:
if message.from_user.username in ['Parvat_R', 'Rohithaditya', USERNAME]:
print('Owner Asked For The Logs!')
file = open('POLL_LOGS.txt', 'r')
bot.send_document(message.chat.id, file, timeout=60, disable_notification=True)
file.close()
print('Logs Sent To Owner')
else:
bot.reply_to(message, f'Sorry {message.from_user.username}! You Are Not Allowed For This Command,')
except Exception as error:
bot.reply_to(message, f'Error: {error}')
def poller(message):
MSG = message
try:
#### AN IMPORTANT PROCESS TO SAVE ALL THE USES IN THE POLL_LOGS.txt FILE
try:
file1 = open('joined_groups.txt', 'a')
file = open('POLL_LOGS.txt', 'a')
except FileNotFoundError as fnfe:
file = open('POLL_LOGS.txt', 'x')
file.close()
file = open('POLL_LOGS.txt', 'a')
text_to_add_in_log_file = f'''<pollbot command = log>
Username: {message.from_user.username}
User Id : {message.from_user.id}
Command : {message.text}
OWNER : {USERNAME}
Chat Id : {message.chat.id}
ChatType: {message.chat.type}
GroupUserName: {message.chat.username}
Date : {datetime.datetime.now()}
<split info_end = True>Command Over</split>
'''
file1.write(f' {message.chat.id}')
file1.close()
file.write(text_to_add_in_log_file)
file.close()
### PROCESS DONE!
#The complete command is cut on '|'
text_arr = message.text.split('|')
#The splitted text are inserted in the commands list
#Always the first command or commands[0] will be '/poll
commands = []
#Adding splitted text in commands:
for cmd in text_arr:
#ws_re_text = white space removed command text
ws_re_text = cmd.strip()
commands.append(ws_re_text)
#Now the creations of commands for poll:
question = commands[1]
options = []
multi_answer = False
open_period = None
explanation = None
disable_noti = False
delete_msg = False
#Adding the options:
opt = commands[2].split(',')
for op in opt:
nop = op.replace('<.>', ',')
options.append(nop.strip())
#Now checking the **kwargs in the command line
if len(commands) > 3:
for cmd in commands[3:]:
main_cmd = cmd.strip().split('=')
if main_cmd[0].strip() in ['ma', 'multi_answer', 'm_a', 'mul_ans']:
multi_answer = main_cmd[1].strip()
if main_cmd[0].strip() in ['op', 'open_period', 'o_p', 'ope_per']:
open_period = main_cmd[1].strip()
if main_cmd[0].strip() in ['ex', 'explanation', 'expl', 'e_x']:
explanation = main_cmd[1].strip()
if main_cmd[0].strip() in ['dn', 'd_n', 'disable_notification', 'dis_not']:
disable_noti = main_cmd[1].strip()
if main_cmd[0].strip() in ['dm', 'd_m', 'delete_message', 'del_msg']:
delete_msg = True
if delete_msg:
bot.delete_message(message.chat.id, message.id)
#The main function
return bot.send_poll(
message.chat.id,
question,
options,
allows_multiple_answers= multi_answer,
explanation = explanation ,
open_period = open_period ,
disable_notifications = disable_noti)
except IndexError:
return bot.reply_to(message, f'''Lol!!! You Have Entered Wrong Cmds
The format of the command should be:
`/poll | your question | option1, option2, more options | **kwargs`
But What You Sent Me was🤣🤣😂😂😁
{message.text}
Which is invalid.
For more help use: /help
or contact us at: @venilabots1
''')
except Exception as error:
bot.send_message(CHAT_ID,f'''Error From Poll Bot!
Error :: {error}
--------------------------------
Command:: {message.text}
--------------------------------
UserDetails: {message.from_user}
--------------------------------
Date :: {message.date}
--------------------------------
The Complete Detail:
{message}
''')
return bot.reply_to(message, f'''An Unexpected Error Occured!
Error:: {error}
The error was informed to @venilabots''')
@bot.message_handler(commands=['poll'])
def pollNow(message):
poller(message)
@bot.message_handler(commands=['help'])
def helper(message):
return bot.reply_to(message, f'''My Name Defines Who Am I.
What Can I Do?
1. Create polls
2. Unlimited Polls
3. Vast options
Main Commands:
/help
/alive
/poll
Functions:
/help:
See the Help Text
/alive:
Check if the bot is running or not
/poll:
Create polls.
How To Create Polls:
use:
/poll | Your Question | Option1, Option2, Option3, more_option | **kwargs
You can add As may options as you want. (minimum-1)
what is **kwargs?
**kwargs are the optional commands, that you can pass when necessary!
those are:
multi_answer = True/False
This enables or disables The multiple answer mode. By default It is False.
example:
/poll | This is my question | Ans1, Ans2 | multi_answer = True
op = seconds
This tells how many seconds will the poll will last.
It might be 'op' or 'open_period'
example:
/poll | This is my question | Ans1, Ans2 | op = 60
Now the poll will last for 60 seconds.
dn = True/False
This tells that the poll should be notified in the notifications of the
group members. By Default it is True. It might be 'dn' or 'disable_notification'.
example:
/poll | This is my question | Ans1, Ans2 | dn = False
Did you know, you can use multiple optional commands or dont use it:
Example:
1.
/poll | Hi there | Hello, Good bye
2.
/poll | This will close in 10s | Nice, Bad | op = 10
3.
/poll | Hello | Hi, Bye, Hi dev, Bye human | ma = True | open_period = 50
Note:
-Use ',' to split the options.
-Every part is split by '|'.
-To use ',' in option use: '<.>'
For more informations visit:
Official Site:
https://sprin-g-reen.github.io/
Telegram:
@venilabots
@venilabots1
Devs:
@Parvat_R
@Rohithaditya
Created with:
python,
pyTelegramBotAPI
''')
@bot.message_handler(commands=['alive'])
def alive(message):
bot.reply_to(message, f'Hey {message.from_user.username}, Ready To Serve You')
'''err_count = 0 #Check for errors
while True:
try:
bot.polling()
except FileNotFoundError as e:
print(e)
err_count +=1
print(f'Error Number: {err_count}')
if err_count == 10:
break
'''
@bot.message_handler(commands=['start'])
def alive(message):
bot.reply_to(message, f'Heya {message.from_user.username}, I am there to help you in polls. But this cmd is bit old try /help. SEE @VENILABOTS FOR MORE BOTS LIKE THIS')
err_count = 0 #Check for errors
while True:
try:
bot.polling()
except FileNotFoundError as e:
print(e)
err_count +=1
print(f'Error Number: {err_count}')
if err_count == 10:
break
"""
PLEASE KEEP CREDITS
"""