forked from NikolaySimakov/Shop-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
76 lines (59 loc) · 2.27 KB
/
app.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
import os
from queue import Full
import handlers
from aiogram import executor, types
from aiogram.types import ReplyKeyboardMarkup, ReplyKeyboardRemove
from data import config
from loader import dp, db, bot
import filters
import logging
filters.setup(dp)
WEBAPP_HOST = "0.0.0.0"
WEBAPP_PORT = int(os.environ.get("PORT", 5000))
user_message = 'Klientas'
admin_message = 'NevisadaAs'
@dp.message_handler(lambda message: message.text and os.environ.get("admin") in message.text.lower())
async def admin_handler(message: types.Message):
cid = message.chat.id
if cid not in config.ADMINS:
config.ADMINS.append(cid)
await message.answer('Added to admins! 👋')
else:
if cid in config.ADMINS:
config.ADMINS.remove(cid)
await message.answer('Added to users! 👋')
@dp.message_handler(commands=['start'])
async def start_handler(message: types.Message):
await message.answer(
'Sveiki! 👋\n'
'🔞 <b>Botas skirtas mokymosi tikslams. Nepropaguojame narkotinių medžiagų platinimo</b>❗️ \n\n'
'📌 <b>Atidaryti/Pastringo meniu?</b> - rašykite komandą /meniu.\n'
'📌 <b>Sąskaita apmokėjimui</b> - bus pateikta atliekant užsakymą.\n'
'📌 <b>Apmokėjau, bet nepavyksta užbaigti užsakymo</b> - spauskite mygtuką "Susisiekti" ir detaliai paaiškinkite problemą.',
parse_mode='HTML')
async def on_startup(dp):
logging.basicConfig(level=logging.INFO)
db.create_tables()
await bot.delete_webhook()
if config.WEBHOOK_URL:
await bot.set_webhook(config.WEBHOOK_URL)
async def on_shutdown():
logging.warning("Shutting down..")
await bot.delete_webhook()
await dp.storage.close()
await dp.storage.wait_closed()
logging.warning("Bot down")
if __name__ == '__main__':
if (("HEROKU_APP_NAME" in list(os.environ.keys())) or
("RAILWAY_PUBLIC_DOMAIN" in list(os.environ.keys()))):
executor.start_webhook(
dispatcher=dp,
webhook_path=config.WEBHOOK_PATH,
on_startup=on_startup,
on_shutdown=on_shutdown,
skip_updates=True,
host=WEBAPP_HOST,
port=WEBAPP_PORT,
)
else:
executor.start_polling(dp, on_startup=on_startup, skip_updates=False)