Completed
Push — master ( 322940...55aad5 )
by Anas
34s
created

Globals.__init__()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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