some cosmetics and case statements
This commit is contained in:
parent
35da34bc8c
commit
c4f65650b9
3 changed files with 16 additions and 12 deletions
|
@ -1,5 +1,3 @@
|
||||||
""" Some functions for api calls """
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
@ -31,14 +29,15 @@ class ApiWrapper:
|
||||||
# this could have used match - case statement, but python 3.9
|
# this could have used match - case statement, but python 3.9
|
||||||
def call(self, api: str, data: typing.Union[str, None],
|
def call(self, api: str, data: typing.Union[str, None],
|
||||||
message: str) -> str:
|
message: str) -> str:
|
||||||
if api == 'img_url': return self.format_img(data)
|
match api:
|
||||||
elif api == 'gif': return self.get_gif()
|
case 'img_url': return self.format_img(data)
|
||||||
elif api == 'kmp': return self.get_kmp()
|
case 'gif': return self.get_gif()
|
||||||
elif api == 'fga': return self.get_fga()
|
case 'kmp': return self.get_kmp()
|
||||||
elif api == 'fakenews': return self.get_fakenews()
|
case 'fga': return self.get_fga()
|
||||||
elif api == 'anek': return self.get_anek()
|
case 'fakenews': return self.get_fakenews()
|
||||||
elif api == 'y_search': return self.y_search(message)
|
case 'anek': return self.get_anek()
|
||||||
return self.FAILED
|
case 'y_search': return self.y_search(message)
|
||||||
|
case _: return self.FAILED
|
||||||
|
|
||||||
def __sanitize_search(self, message: str) -> str:
|
def __sanitize_search(self, message: str) -> str:
|
||||||
"""Removes one of each of the search tokens from the query
|
"""Removes one of each of the search tokens from the query
|
||||||
|
|
|
@ -30,6 +30,7 @@ class Cron:
|
||||||
|
|
||||||
def __mkjob(self, job: dict) -> callable:
|
def __mkjob(self, job: dict) -> callable:
|
||||||
tokens = frozenset(job['tokens'].split(','))
|
tokens = frozenset(job['tokens'].split(','))
|
||||||
|
|
||||||
async def send_message() -> None:
|
async def send_message() -> None:
|
||||||
if 'rand' in job:
|
if 'rand' in job:
|
||||||
wait_seconds = random.randint(0, job['rand']) * 60
|
wait_seconds = random.randint(0, job['rand']) * 60
|
||||||
|
|
|
@ -32,10 +32,14 @@ class MiscReactor:
|
||||||
|
|
||||||
def spawn_edited_handler(self,
|
def spawn_edited_handler(self,
|
||||||
client: telethon.TelegramClient,
|
client: telethon.TelegramClient,
|
||||||
trigger: telethon.events.common.EventBuilder) -> None:
|
trigger: telethon.events.common.EventBuilder
|
||||||
|
) -> None:
|
||||||
@client.on(trigger)
|
@client.on(trigger)
|
||||||
async def handle_edited_message(event):
|
async def handle_edited_message(event):
|
||||||
sender = await event.get_sender()
|
sender = await event.get_sender()
|
||||||
sender_name = self.namegen.get_name(sender)
|
sender_name = self.namegen.get_name(sender)
|
||||||
chat_id = event.message.peer_id
|
chat_id = event.message.peer_id
|
||||||
await client.send_message(chat_id, f'Я всё видел! {sender_name} совсем охуел, сообщения правит!')
|
await client.send_message(
|
||||||
|
chat_id,
|
||||||
|
f'Я всё видел! {sender_name} совсем охуел, сообщения правит!'
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue