-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_server.py
41 lines (33 loc) · 1.07 KB
/
simple_server.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
from sanic import Sanic
from sanic.log import logger
from sanic.response import text, empty
from aiogram import Bot
from aiogram.utils.exceptions import BadRequest
TOKEN = "MUSS-MIT-TOKEN-ERSETZT-WERDEN"
app = Sanic("TecDaysSimpleServer")
bot = Bot(token=TOKEN)
app.static('/public', './public')
@app.get("/")
async def say_hello(request):
return text("Hello")
@app.get("/setScore")
async def set_score(request):
user_id = request.args.get('uid')
score = request.args.get('score', 0)
inline_message_id = request.args.get('imid', None)
message_id = request.args.get('mid', None)
chat_id = request.args.get('cid', None)
try:
await bot.set_game_score(
user_id=user_id,
score=int(score),
inline_message_id=inline_message_id,
message_id=message_id,
chat_id=chat_id
)
logger.info(f"Score updated {score}")
except BadRequest as e:
logger.info(f"Score unchanged {score}")
return empty(status=304)
return empty(status=200)
app.run(host="0.0.0.0", port=8080)