From 3b8ccffe23f77b9834c3107bb716782f64c4e75c Mon Sep 17 00:00:00 2001 From: clockblocker <asde3211q@gmail.com> Date: Sun, 26 Dec 2021 18:28:03 +0300 Subject: [PATCH] Refactor blyad --- clockblocker_bot/actions/basic.py | 15 ++++++++++----- clockblocker_bot/utils/rotate_words.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 clockblocker_bot/utils/rotate_words.py diff --git a/clockblocker_bot/actions/basic.py b/clockblocker_bot/actions/basic.py index 7c3cc2c..6423561 100644 --- a/clockblocker_bot/actions/basic.py +++ b/clockblocker_bot/actions/basic.py @@ -7,6 +7,7 @@ from datetime import datetime from clockblocker_bot.config import config from clockblocker_bot.utils.constants import CLOCKBLOCKER_ID, S3RIUS_ID +from clockblocker_bot.utils.rotate_words import rotate_words from clockblocker_bot.utils.decorators import ( beware_the_croud_policy, clean_up_policy, @@ -24,6 +25,7 @@ logger = logging.getLogger(__name__) @clean_up_policy async def show_help(event: events.NewMessage.Event): help_text = Path(__file__).parent / "static_messages" / "help.txt" + print('h') with open(help_text) as f: contents = f.read() return await event.respond(contents) @@ -42,19 +44,22 @@ async def ci(event: events.NewMessage.Event): @config.telegram_client.on( events.NewMessage( - pattern=re.compile(".*([Бб]Ñлдь|,zklm|[Бб]лÑдь).*", flags=re.DOTALL | re.MULTILINE), + pattern=re.compile(r".*(БлÑдь|БлsDÑŒ|лÑбдь|,zklm|блÑдь|БлÑдь|блÑьд|БлÑьд).*", flags=re.DOTALL | re.MULTILINE), outgoing=True, ) ) @mark_unread async def blyad(event: events.NewMessage.Event): - permutations = set(["БлÑдь", "БлasDÑŒ", "лÑбдь", ",zklm", "блÑдь", "БлÑдь", "блÑьд", "БлÑьд"]) + blyads = ["БлÑдь", "БлsDÑŒ", "лÑбдь", ",zklm", "блÑдь", "БлÑдь", "блÑьд", "БлÑьд"] start_time = datetime.now() current_time = start_time - last_blyad = event.message.message + s = event.message.message + print('blyad') + while (current_time - start_time).seconds < 10: - last_blyad = random.choice(list(permutations - set(last_blyad))) - await event.message.edit(last_blyad) + s = rotate_words(s, blyads) + print('message: ', event.message.message, s) + await event.message.edit(s) await asyncio.sleep(1) current_time = datetime.now() diff --git a/clockblocker_bot/utils/rotate_words.py b/clockblocker_bot/utils/rotate_words.py new file mode 100644 index 0000000..b555209 --- /dev/null +++ b/clockblocker_bot/utils/rotate_words.py @@ -0,0 +1,17 @@ +import re +from random import randint +from copy import copy + +def pick_another(word, words): + while len(words) > 1: + i = randint(0, len(words) - 1) + if (words[i] != word): + return words[i] + +def rotate_words(s, words): + result = copy(s) + indices_pairs = [(m.start(0), m.end(0)) for m in re.finditer('|'.join(words), s)] + for indices_pair in indices_pairs: + i, j = indices_pair + result = result[:i] + pick_another(result[i:j], words) + result[j:] + return result \ No newline at end of file -- GitLab