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
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))