Config: 0.3.1

This commit is contained in:
Christian Rendina 2020-03-09 01:18:21 +01:00
parent a50e046583
commit 4202b02904
2 changed files with 45 additions and 6 deletions

7
config.ini Normal file
View File

@ -0,0 +1,7 @@
[Api]
Url=
Id=
Password=
[Bot]
Token=

View File

@ -7,7 +7,6 @@ import logging
from telegram import InlineQueryResultArticle, InputTextMessageContent, Bot from telegram import InlineQueryResultArticle, InputTextMessageContent, Bot
import uuid import uuid
import requests import requests
import password
BOT_VERSION = "0.3" BOT_VERSION = "0.3"
@ -45,15 +44,48 @@ class Command:
def getHeaderField(self): def getHeaderField(self):
return self.headerField 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: class InlineBot:
def __init__(self): def __init__(self):
self.apiUrl = password.API_URL self.apiUrl = password.API_URL
self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;" self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;"
self.commands = [] self.commands = []
self.config = None
#self.__loadConfig() ## todo v0.3.1 self.__loadConfig() ## todo v0.3.1
self.__makeCommands() self.__makeCommands()
def __loadConfig(self):
self.config = Config()
self.config.read("config.ini")
def __makeCommands(self): def __makeCommands(self):
cmd = Command() cmd = Command()
@ -93,10 +125,10 @@ class InlineBot:
if not command: if not command:
return self.errorText return self.errorText
r = requests.get(self.apiUrl, r = requests.get(self.config.getApiUrl(),
headers={ headers={
"botid":password.BOT_ID, "botid":self.config.getApiId(),
"botpassword":password.BOT_PASSWORD, "botpassword":self.config.getApiPassword(),
"command":command.getName().lower(), "command":command.getName().lower(),
"replytouserid":"0", "replytouserid":"0",
"senderuserid":senderid, "senderuserid":senderid,
@ -117,7 +149,7 @@ class InlineBot:
return r.headers[command.getHeaderField()] return r.headers[command.getHeaderField()]
def start(self): 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) self.updater = Updater(bot=self.bot,use_context=True)
print("Inline bot v. {}".format(BOT_VERSION)) print("Inline bot v. {}".format(BOT_VERSION))