app.bot   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 24
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A delete() 0 8 1
A webhook() 0 10 1
A get_message() 0 8 1
A index() 0 8 1
1
"""
2
Providing routes for our application
3
"""
4
5
from quart import Blueprint, request as rq
6
from telebot import types
7
8
from app.bot.telegram import bot, TOKEN
9
10
bot_blueprint = Blueprint("route", __name__)
11
12
13
@bot_blueprint.route(f"/{TOKEN}", methods=["POST"])
14
async def get_message():
15
    """
16
    Get all messages
17
    :return:
18
    """
19
    await bot.process_new_updates([types.Update.de_json(await rq.get_json())])
20
    return "Ok", 200
21
22
23
@bot_blueprint.route("/about")
24
async def index():
25
    """
26
    Test functionality
27
    :return:
28
    """
29
    bot_data = await bot.get_me()
30
    return {k: v for k, v in bot_data.to_dict().items() if v}, 200
31
32
33
@bot_blueprint.route("/set")
34
async def webhook():
35
    """
36
    Set telegram webhook
37
    :return:
38
    """
39
    app_site = rq.host
40
    await bot.remove_webhook()
41
    await bot.set_webhook(url=f"https://{app_site}/bot/{TOKEN}")
42
    return "⚓ Webhook was set.", 200
43
44
45
@bot_blueprint.route("/del")
46
async def delete():
47
    """
48
    Delete telegram webhook
49
    :return:
50
    """
51
    await bot.remove_webhook()
52
    return "🔱 Webhook was deleted.", 200
53