From 4202b0290404c39b725da9c936a9d3e60a1001ea Mon Sep 17 00:00:00 2001 From: Arves100 Date: Mon, 9 Mar 2020 01:18:21 +0100 Subject: [PATCH] Config: 0.3.1 --- config.ini | 7 +++++++ inline.py | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..7986f38 --- /dev/null +++ b/config.ini @@ -0,0 +1,7 @@ +[Api] +Url= +Id= +Password= + +[Bot] +Token= diff --git a/inline.py b/inline.py index 6b77167..d174d10 100644 --- a/inline.py +++ b/inline.py @@ -7,7 +7,6 @@ import logging from telegram import InlineQueryResultArticle, InputTextMessageContent, Bot import uuid import requests -import password BOT_VERSION = "0.3" @@ -44,16 +43,49 @@ class Command: def getHeaderField(self): return self.headerField + +class Config: + def __init__(self): + self.apiUrl = "" + self.apiId = "" + self.apiPassword = "" + self.botToken = "" + + def read(self, name): + import configparser + cfg = configparser.ConfigParser() + cfg.read(name) + self.apiUrl = cfg["Api"]["Url"] + self.apiId = cfg["Api"]["Id"] + self.apiPassword = cfg["Api"]["Password"] + self.botToken = cfg["Bot"]["Token"] + + def getApiUrl(self): + return self.apiUrl + + def getApiId(self): + return self.apiId + + def getApiPassword(self): + return self.apiPassword + + def getBotToken(self): + return self.botToken class InlineBot: def __init__(self): self.apiUrl = password.API_URL self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;" self.commands = [] + self.config = None - #self.__loadConfig() ## todo v0.3.1 + self.__loadConfig() ## todo v0.3.1 self.__makeCommands() + def __loadConfig(self): + self.config = Config() + self.config.read("config.ini") + def __makeCommands(self): cmd = Command() @@ -93,10 +125,10 @@ class InlineBot: if not command: return self.errorText - r = requests.get(self.apiUrl, + r = requests.get(self.config.getApiUrl(), headers={ - "botid":password.BOT_ID, - "botpassword":password.BOT_PASSWORD, + "botid":self.config.getApiId(), + "botpassword":self.config.getApiPassword(), "command":command.getName().lower(), "replytouserid":"0", "senderuserid":senderid, @@ -117,7 +149,7 @@ class InlineBot: return r.headers[command.getHeaderField()] def start(self): - self.bot = Bot(token=password.BOT_TOKEN) + self.bot = Bot(token=self.config.getBotToken()) self.updater = Updater(bot=self.bot,use_context=True) print("Inline bot v. {}".format(BOT_VERSION))