Skip to content

Commit 7d6714e

Browse files
authored
Refactor bot to use telebot_bot instance
1 parent cca05b8 commit 7d6714e

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

telegram.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
# response = requests.post(url, headers=headers)
6565
# print(response.status_code)
6666

67+
from telebot import apihelper
68+
69+
apihelper.ENABLE_MIDDLEWARE = True # Must be before TeleBot init
70+
6771

6872
def listener(messages):
6973
"""
@@ -427,10 +431,10 @@ def listToString(s):
427431
return str1.join(s)
428432

429433

430-
@bot.message_handler(commands=["bar"])
434+
@telebot_bot.message_handler(commands=["bar"])
431435
def command_bar(message: Message):
432436
cid = message.chat.id
433-
chat = bot.get_chat(message.chat.id)
437+
chat = telebot_bot.get_chat(message.chat.id)
434438
mention = []
435439
for i in bar_members:
436440
if "username" in bar_members[i]:
@@ -444,22 +448,22 @@ def command_bar(message: Message):
444448
print(mention)
445449
push_alert = listToString(mention)
446450
print(push_alert)
447-
bot.send_message(cid, f"{push_alert} GO BAR", parse_mode="HTML")
448-
bot.send_poll(
451+
telebot_bot.send_message(cid, f"{push_alert} GO BAR", parse_mode="HTML")
452+
telebot_bot.send_poll(
449453
cid,
450454
"DRINK BEER SAVE WATER",
451455
["Drink beer", "Discord", "Play computer"],
452456
is_anonymous=False,
453457
)
454458
pic_choice = random.choice(beer_photo)
455-
bot.send_photo(cid, pic_choice)
459+
telebot_bot.send_photo(cid, pic_choice)
456460
# bot.send_poll(cid, 'Poll', {
457461
# "Drink beer",
458462
# "Play computer"
459463
# })
460464

461465

462-
@bot.message_handler(
466+
@telebot_bot.message_handler(
463467
commands=["mem", "tupian"]
464468
) # tupian = 图片 (image in Chinese Pinyin)
465469
def command_mem(message: Message):
@@ -473,11 +477,11 @@ def command_mem(message: Message):
473477
for i in range(0, count_memes):
474478
mem.append(json_data["data"]["memes"][i]["url"])
475479
random.shuffle(mem)
476-
bot.send_photo(cid, mem[0])
480+
telebot_bot.send_photo(cid, mem[0])
477481

478482

479483
# test api
480-
@bot.message_handler(
484+
@telebot_bot.message_handler(
481485
commands=["getimage", "image", "huoqutupian"]
482486
) # huoqutupian = 获取图片 (get image in Chinese Pinyin)
483487
def command_image(message: Message):
@@ -491,10 +495,10 @@ def command_image(message: Message):
491495
for i in range(0, count_memes):
492496
image.append(json_data["data"]["memes"][i]["url"])
493497
random.shuffle(image)
494-
bot.send_photo(cid, image[0])
498+
telebot_bot.send_photo(cid, image[0])
495499

496500

497-
@bot.message_handler(commands=["meme"])
501+
@telebot_bot.message_handler(commands=["meme"])
498502
def command_mem(message: Message):
499503
cid = message.chat.id
500504
r = requests.get("https://api.imgflip.com/get_memes")
@@ -508,7 +512,7 @@ def command_mem(message: Message):
508512
meme.append(json_data["data"]["memes"][i]["url"])
509513
# print(mem[i])
510514
random.shuffle(meme)
511-
bot.send_photo(cid, meme[0])
515+
telebot_bot.send_photo(cid, meme[0])
512516

513517

514518
@bot.message_handler(commands=["help_auth"])

0 commit comments

Comments
 (0)