Passed
Push — master ( 9bfda5...dc2491 )
by Anas
02:12
created

rikkabot.start()   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nop 2
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from telegram.ext import Updater, CommandHandler
4
from random import randint
5
import importlib
6
import datetime
7
import yaml
8
import os
9
import re
10
11
class Globals:
12
    def __init__(self, updater, dp, config):
13
        self.updater = updater
14
        self.dp = dp
15
        self.config = config
16
17
# Import logo from a text file
18
with open("resources/logo.txt", "r", encoding="UTF-8") as logo_file:
19
    logo = logo_file.read()
20
    print(logo)
21
22
# Load configs & create folders
23
with open("config.yml", "r") as f:
24
    config = yaml.load(f)
25
key = config["keys"]["telegram_token"]
26
updater = Updater(token=key)
27
dp = updater.dispatcher
28
29
for feature in config["features"]:
30
    if "path" in config["features"][feature]:
31
        path = config["features"][feature]["path"]
32
        if not os.path.exists(path):
33
            os.makedirs(path)
34
    if config["features"][feature]["enabled"] is True:
35
        module_config = config["features"][feature]
36
        global_data = gd = Globals(updater, dp, module_config)
37
        module = importlib.import_module("modules." + feature).module_init(gd)
38
        print(feature)
39
40
# Import /help from a text file
41
with open("resources/help.txt", "r", encoding="UTF-8") as helpfile:
42
    help_text = helpfile.read()
43
    print("Help textfile imported")
44
45
46
# Start feature
47
def start(bot, update):
48
    if update.message.chat.type != "private":
49
        return
50
    with open("resources/hello.webp", "rb") as hello:
51
        update.message.reply_sticker(hello, quote=False)
52
    personname = update.message.from_user.first_name
53
    update.message.reply_text("Konnichiwa, " + personname + "! \nMy name is Takanashi Rikka desu! \
54
                              \nUse /help to see what I can do! :3", quote=False)
55
    print(datetime.datetime.now(), ">>>", "Done /start", ">>>", update.message.from_user.username)
56
dp.add_handler(CommandHandler("start", start))
57
58
59
# Show help
60
def help(bot, update):
61
    bot.send_message(update.message.chat_id, help_text, parse_mode="Markdown")
62
    print(datetime.datetime.now(), ">>>", "Done /help", ">>>", update.message.from_user.username)
63
dp.add_handler(CommandHandler("help", help))
64
65
# Starting bot
66
updater.start_polling(clean=True, bootstrap_retries=0, read_latency=1.0)
67
# Run the bot until you presses Ctrl+C
68
print("=====================\nUp and running!\n")
69
#Idle
70
updater.idle()
71