added type hints for function parameters and return values
Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
parent
d2989e4857
commit
53c742035b
1 changed files with 8 additions and 9 deletions
|
@ -47,7 +47,7 @@ datum = None
|
||||||
|
|
||||||
class HSMensaW(telepot.aio.helper.ChatHandler):
|
class HSMensaW(telepot.aio.helper.ChatHandler):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def on_chat_message(msg):
|
async def on_chat_message(msg: dict) -> None:
|
||||||
global config, essen, status, var
|
global config, essen, status, var
|
||||||
|
|
||||||
content_type, chat_type, chat_id = telepot.glance(msg)
|
content_type, chat_type, chat_id = telepot.glance(msg)
|
||||||
|
@ -114,7 +114,7 @@ class HSMensaW(telepot.aio.helper.ChatHandler):
|
||||||
write_config()
|
write_config()
|
||||||
|
|
||||||
|
|
||||||
async def send_essen(chat_id):
|
async def send_essen(chat_id: int) -> None:
|
||||||
global datum, essen
|
global datum, essen
|
||||||
nachricht = "Speiseplan am %s, den %s:\n" % (wochentage[datum.weekday()], datum.strftime("%d. MONAT %Y"))
|
nachricht = "Speiseplan am %s, den %s:\n" % (wochentage[datum.weekday()], datum.strftime("%d. MONAT %Y"))
|
||||||
nachricht = nachricht.replace("MONAT", monate[(datum.month - 1) % 12])
|
nachricht = nachricht.replace("MONAT", monate[(datum.month - 1) % 12])
|
||||||
|
@ -123,7 +123,7 @@ async def send_essen(chat_id):
|
||||||
send_message(bot_obj=bot, chat_id=chat_id, msg=nachricht, parse_mode="markdown")
|
send_message(bot_obj=bot, chat_id=chat_id, msg=nachricht, parse_mode="markdown")
|
||||||
|
|
||||||
|
|
||||||
async def send_status(text):
|
async def send_status(text: str) -> None:
|
||||||
global config_ids
|
global config_ids
|
||||||
for chat_id in config_ids:
|
for chat_id in config_ids:
|
||||||
send_message(bot_obj=bot, chat_id=chat_id, msg=text)
|
send_message(bot_obj=bot, chat_id=chat_id, msg=text)
|
||||||
|
@ -143,8 +143,7 @@ def send_message(bot_obj: DelegatorBot, chat_id: int, msg: str, parse_mode: Any
|
||||||
ids.remove(chat_id)
|
ids.remove(chat_id)
|
||||||
config['ids'] = ids
|
config['ids'] = ids
|
||||||
|
|
||||||
chat = get_chat_name(msg=msg)
|
await send_status("Bot wurde blockiert für Chat ID %i)" % chat_id)
|
||||||
await send_status("Bot wurde blockiert für Chat %s (ID: %i)" % (chat, chat_id))
|
|
||||||
|
|
||||||
write_config()
|
write_config()
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ def write_config() -> None:
|
||||||
json.dump(config, outfile)
|
json.dump(config, outfile)
|
||||||
|
|
||||||
|
|
||||||
async def get_essen(only_today):
|
async def get_essen(only_today: bool) -> None:
|
||||||
global datum, essen, var # , ctx
|
global datum, essen, var # , ctx
|
||||||
essen = []
|
essen = []
|
||||||
try:
|
try:
|
||||||
|
@ -202,7 +201,7 @@ async def get_essen(only_today):
|
||||||
essen.append(Essen(name, preis, kategorie))
|
essen.append(Essen(name, preis, kategorie))
|
||||||
|
|
||||||
|
|
||||||
def get_bot_id():
|
def get_bot_id() -> int:
|
||||||
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
|
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
|
||||||
with urllib.request.urlopen(api_url) as response:
|
with urllib.request.urlopen(api_url) as response:
|
||||||
data = json.load(response)
|
data = json.load(response)
|
||||||
|
@ -210,7 +209,7 @@ def get_bot_id():
|
||||||
return bot_id
|
return bot_id
|
||||||
|
|
||||||
|
|
||||||
def get_chat_name(msg):
|
def get_chat_name(msg: dict) -> str:
|
||||||
if msg["chat"]["type"] == "group":
|
if msg["chat"]["type"] == "group":
|
||||||
chat = msg["chat"]["title"] + " (g)"
|
chat = msg["chat"]["title"] + " (g)"
|
||||||
elif msg["chat"]["type"] == "private":
|
elif msg["chat"]["type"] == "private":
|
||||||
|
@ -230,7 +229,7 @@ def shutdown(signum, frame):
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
async def essen_loop():
|
async def essen_loop() -> None:
|
||||||
global status, essen, ids
|
global status, essen, ids
|
||||||
while True:
|
while True:
|
||||||
now = datetime.datetime.today()
|
now = datetime.datetime.today()
|
||||||
|
|
Loading…
Reference in a new issue