Completed
Branch master (dc416b)
by Anas
02:28
created

load_modules()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler
2
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
3
from random import randint
4
import importlib
5
import datetime
6
import logging
7
import yaml
8
import os
9
import re
10
11
with open("config.yml", "r") as f:
12
    key = yaml.load(f)["keys"]["telegram_token"]
13
updater = Updater(token=key)
14
dp = updater.dispatcher
15
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
16
17
18
def load_modules(dp, *modules):
19
    for i in modules:
20
        importlib.import_module("modules." + i).handler(dp)
21
        print(i, "imported")
22
23
load_modules(dp,
24
             "anime",
25
             "bing_search",
26
             "instagram",
27
             "gif",
28
             "glitch",
29
             "kappa",
30
             "kek",
31
             "leetspeak",
32
             "lego",
33
             "liquid",
34
             "meme",
35
             "nya",
36
             "pcstat",
37
             "roll",
38
             "toribash")
39
40
# Import /help from a text file
41
with open("resources/help.txt", "r") as helpfile:
42
    help_text = helpfile.read()
43
    print("Help textfile imported")
44
45
46
# start feature
47
def start(bot, update):
48
    with open("resources/hello.webp", "rb") as hello:
49
        update.message.reply_sticker(hello, quote=False)
50
    personname = update.message.from_user.first_name
51
    update.message.reply_text("Konnichiwa, " + personname + "! \nMy name is Takanashi Rikka desu! \
52
                              \nUse /help to see what I can do! :3", quote=False)
53
    print(datetime.datetime.now(), ">>>", "Done /start", ">>>", update.message.from_user.username)
54
dp.add_handler(CommandHandler("start", start))
55
56
57
# show help
58
def help(bot, update):
59
    update.message.reply_text(help_text)
60
    print(datetime.datetime.now(), ">>>", "Done /help", ">>>", update.message.from_user.username)
61
dp.add_handler(CommandHandler("help", help))
62
63
# Starting bot
64
updater.start_polling(clean=True)
65
# Run the bot until you presses Ctrl+C
66
print("=====================\nUp and running!\n")
67
updater.idle()
68