add shitpost plugins

This commit is contained in:
eyezis 2018-06-03 14:16:14 +02:00
parent 95fd4eec97
commit d04d082c45
2 changed files with 77 additions and 0 deletions

37
stdplugins/sp_badregex.py Normal file
View File

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

View File

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