forked from Sets88/sets88_telegram_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
59 lines (44 loc) · 1.78 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
import asyncio
from telebot import ExceptionHandler
from telebot.types import Message
from telebot.asyncio_storage import StateMemoryStorage
from telebot_nav import TeleBotNav
from config import TELEGRAM_TOKEN
from config import ALLOWED_USER_NAMES
import config
import openai_module
import replicate_module
import youtube_dl_module
from logger import logger
class ExceptionH(ExceptionHandler):
def handle(self, exception: Exception):
logger.exception(exception)
async def start(botnav: TeleBotNav, message: Message) -> None:
logger.info(f'{message.from_user.username} {message.chat.id}')
if (ALLOWED_USER_NAMES and botnav.get_user(message).username.lower() not in ALLOWED_USER_NAMES):
logger.info(f'{message.from_user.username} {message.chat.id} not allowed')
await botnav.bot.send_message(message.chat.id, "Build your own bot here is a source code: https://github.com/Sets88/sets88_telegram_bot")
return
await botnav.print_buttons(
message.chat.id,
{
'🧠 OpenAI': openai_module.start_openai if config.OPENAI_API_KEY else None,
'💻 Replicate': replicate_module.start_replicate if config.REPLICATE_API_KEY else None,
'📼 Youtube-DL': youtube_dl_module.start_youtube_dl,
}, 'Choose',
row_width=2
)
botnav.wipe_commands(message)
botnav.add_command(message, 'start', '🏁 Start the bot', start)
await botnav.send_commands(message)
async def main() -> None:
await botnav.send_init_commands({'start': '🏁 Start the bot'})
await botnav.set_global_default_handler(start)
await botnav.bot.polling()
botnav = TeleBotNav(
TELEGRAM_TOKEN,
state_storage=StateMemoryStorage(),
exception_handler=ExceptionH()
)
if __name__ == '__main__':
asyncio.run(main())