forked from JanisV/release-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.py
37 lines (28 loc) · 987 Bytes
/
routes.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
from http import HTTPStatus
from flask import Response, request
from app import telegram_bot, app
from app.models import Chat, Repo, Release
@app.route('/')
async def index():
bot_me = await telegram_bot.get_me()
return (f'<a href="https://t.me/{bot_me.username}">{bot_me.first_name}</a> - a telegram bot for GitHub releases.'
'<br><br>'
'Source code available at <a href="https://github.com/JanisV/release-bot">release-bot</a>')
@app.route('/stats')
async def stats():
users = Chat.query.count()
repos = Repo.query.count()
releases = Release.query.count()
statistics = {
"users": users,
"repos": repos,
"releases": releases,
}
return statistics
@app.post("/telegram")
async def telegram() -> Response:
if app.config['SITE_URL']:
await telegram_bot.webhook(request.json)
return Response(status=HTTPStatus.OK)
else:
return Response(status=HTTPStatus.NOT_IMPLEMENTED)