Passed
Push — master ( 449b8d...1f3828 )
by torrua
01:12
created

app.bot   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

4 Functions

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