From d04d082c45246298b2ffa1d8e74b98cab4b3ddc6 Mon Sep 17 00:00:00 2001 From: eyezis Date: Sun, 3 Jun 2018 14:16:14 +0200 Subject: [PATCH] add shitpost plugins --- stdplugins/sp_badregex.py | 37 +++++++++++++++++++++++++++++++++ stdplugins/sp_prog_rename.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 stdplugins/sp_badregex.py create mode 100644 stdplugins/sp_prog_rename.py diff --git a/stdplugins/sp_badregex.py b/stdplugins/sp_badregex.py new file mode 100644 index 0000000..aecb04e --- /dev/null +++ b/stdplugins/sp_badregex.py @@ -0,0 +1,37 @@ +import asyncio +from telethon import events + +import re + + +@borg.on(events.NewMessage( + pattern=re.compile(r"^s/((?:\\/|[^/])+)/((?:\\/|[^/])*)(/.*)?"))) +async def on_regex(re_event): + re_msg = re_event.message + + async def filter_botanswer(bot_event): + bot_msg = bot_event.message + if bot_msg.reply_to_msg_id == re_msg.id: + return False + if re_msg.reply_to_msg_id and bot_msg.reply_to_msg_id: + if bot_msg.reply_to_msg_id != re_msg.reply_to_msg_id: + return False + if bot_msg.message and '[[regex]]' in bot_msg.message: + return True + if not (await bot_event.sender).bot: + return False + return True + + if re_event.is_private: + return + + try: + await asyncio.wait_for( + borg.await_event( + events.NewMessage(chats=await re_event.input_chat), + filter_botanswer + ), + timeout=3 + ) + except asyncio.TimeoutError: + await re_event.reply("nice regex bro") diff --git a/stdplugins/sp_prog_rename.py b/stdplugins/sp_prog_rename.py new file mode 100644 index 0000000..048ba07 --- /dev/null +++ b/stdplugins/sp_prog_rename.py @@ -0,0 +1,40 @@ +import asyncio +from telethon import events +from telethon.tl.functions.channels import EditTitleRequest + +import telethon.utils + +import re + +prog_tech_id = 1040270887 +prog_tech_channel = None +default_title = "Programming & Tech" +lock = asyncio.Lock() + + +async def edit_title(title): + global prog_tech_channel + if prog_tech_channel is None: + prog_tech_channel = await borg.get_entity(prog_tech_id) + await borg(EditTitleRequest( + channel=prog_tech_channel, title=title + )) + + +@borg.on(events.NewMessage( + pattern=re.compile(r"(?i)programming (?:&|and) (.+)"), chats=prog_tech_id)) +async def on_name(event): + new_topic = event.pattern_match.group(1).title() + new_title = f"Programming & {new_topic} & Tech" + + if len(new_title) > 255 or lock.locked(): + return + + with (await lock): + await edit_title(new_title) + await asyncio.sleep(80) + await asyncio.sleep(60) + if lock.locked(): + return + with (await lock): + await edit_title(default_title)