-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
52 lines (36 loc) · 1.17 KB
/
main.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
import asyncio
import openai
import aiogram
import config as cfg
from aiogram import Bot, types, Dispatcher
from aiogram.utils import executor
from aiogram.types import ParseMode, ChatActions, Message
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from services.openai.start import register_start
from services.openai.generate_text import register_generate_text
#from services.openai.generate_image import register_generate_image
from commands import set_default_commands
# Set up OpenAI API key
openai.api_key = cfg.AI_TOKEN
storage = MemoryStorage()
def register_all_handlers(dp):
register_start(dp)
register_generate_text(dp)
# register_generate_image(dp)
async def main():
# Set up Telegram bot
bot = Bot(cfg.TG_TOKEN)
dp = Dispatcher(bot, storage=storage)
register_all_handlers(dp)
# start
try:
await set_default_commands(dp)
await dp.start_polling()
except:
print('smth got wrong')
if __name__ == '__main__':
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
print(f"Bot stopped! Error: {KeyboardInterrupt} {SystemExit}")
print("[INFO] Bot stopped")