-
Notifications
You must be signed in to change notification settings - Fork 0
/
waiog.py
183 lines (146 loc) · 5.56 KB
/
waiog.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
import sys
import asyncio
from time import time
from aiohttp import web
from aiogram import F, Router
from aiogram.filters.command import Command
from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application
from confy import WEBHOOK_URL, WEBHOOK_URL_PATH, WEBHOOK_HOST, WEBHOOK_PORT
from event import start, show_help, incoming, go_vote, go_inputs
from stats import show_stats, show_top, show_words, show_words_rate, show_comms, show_games
from utils import dp, bot, try_answer_callback_query, dope_send_message
from utils import logger
router = Router()
def get_prefix(from_user):
userid = from_user.id
uname = from_user.username
fname = from_user.first_name
return f"{userid} {fname} @{uname}"
@router.message(Command("start"))
@dp.message(Command("start"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select START ...")
await dope_send_message(f": : {pref} select START")
await start(userid, message)
logger.info(f"{pref} select START :: {time() - start_time}")
@router.message(Command("stats"))
@dp.message(Command("stats"))
async def docall(message):
start_time = time()
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select STATS ...")
await show_stats(message.from_user.id)
logger.info(f"{pref} select STATS :: {time() - start_time}")
@router.message(Command("help"))
@dp.message(Command("help"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select HELP ...")
await show_help(userid)
logger.info(f"{pref} select HELP :: {time() - start_time}")
@router.message(Command("top10"))
@dp.message(Command("top10"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select TOP10 ...")
await show_top(userid, False)
logger.info(f"{pref} select TOP10 :: {time() - start_time}")
@router.message(Command("top7"))
@dp.message(Command("top7"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select TOP7 ...")
await show_top(userid, True)
logger.info(f"{pref} select TOP7 :: {time() - start_time}")
@router.message(Command("words"))
@dp.message(Command("words"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select WORDS ...")
await show_words(userid)
logger.info(f"{pref} select WORDS :: {time() - start_time}")
@router.message(Command("games"))
@dp.message(Command("games"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select GAMES ...")
await show_games(userid)
logger.info(f"{pref} select GAMES :: {time() - start_time}")
@router.message(Command("comms"))
@dp.message(Command("comms"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select UTILS ...")
await show_comms(userid)
logger.info(f"{pref} select UTILS :: {time() - start_time}")
@router.message(Command("rates"))
@dp.message(Command("rates"))
async def docall(message):
start_time = time()
userid = message.from_user.id
pref = get_prefix(message.from_user)
logger.debug(f"{pref} select RATES ...")
await show_words_rate(userid)
logger.info(f"{pref} select RATES :: {time() - start_time}")
@router.message(F.text)
@dp.message(F.text)
async def docall(message):
start_time = time()
pref = get_prefix(message.from_user)
logger.debug(f"{pref} input {message.text} ...")
await incoming(message.chat.id, message.text)
logger.info(f"{pref} input {message.text} :: {time() - start_time}")
@router.callback_query()
@dp.callback_query()
async def docall(query):
start_time = time()
userid = query.message.chat.id
messid = query.message.message_id
button = query.data
pref = get_prefix(query.message.chat)
logger.debug(f"{pref} button {button} ...")
strips = button.split('_')
if len(strips) > 1:
button = strips[0]
chosen = strips[1]
if button == "press":
await go_inputs(userid, chosen)
await try_answer_callback_query(query.id)
if button == "vote":
await go_vote(userid, chosen, strips[2], query.message.text, messid)
await try_answer_callback_query(query.id, 'Голос принят, спасибо')
logger.info(f"{pref} button {query.data} :: {time() - start_time}")
async def start_longpolling():
await dp.start_polling(bot, skip_updates=False)
async def on_startup(bot):
await bot.set_webhook(WEBHOOK_URL + WEBHOOK_URL_PATH)
def start_webhook():
dp.include_router(router)
dp.startup.register(on_startup)
app = web.Application()
webhook_requests_handler = SimpleRequestHandler(dispatcher=dp, bot=bot)
webhook_requests_handler.register(app, path=WEBHOOK_URL_PATH)
setup_application(app, dp, bot=bot)
web.run_app(app, host=WEBHOOK_HOST, port=WEBHOOK_PORT)
if __name__ == '__main__':
if len(sys.argv) > 1 and (sys.argv[1] == '--polling'):
print('wordie <><> polling <><> mode started')
asyncio.run(start_longpolling())
else:
print('wordie aiobot V^V^ webhook V^V^ mode started')
start_webhook()