From 4f8a1f81166ee7af750d4f21f716dc67d9dae6dd Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Sun, 19 Jul 2020 19:22:50 +0400
Subject: [PATCH] Updated rotations. Description: - Cleaned up rotor. - Added
 new public feature.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 src/actions/fun.py       | 20 ++++++++++++++++++++
 src/utils/str_helpers.py |  7 +------
 static_messages/help.txt |  2 ++
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/actions/fun.py b/src/actions/fun.py
index e2da0cd..cb06636 100644
--- a/src/actions/fun.py
+++ b/src/actions/fun.py
@@ -1,9 +1,12 @@
+import asyncio
 import logging
 import random
 import re
+from datetime import datetime
 
 from src.config import config
 from src.utils.responses import mark_unread
+from src.utils.str_helpers import Rotor
 from telethon import events
 
 logger = logging.getLogger(__name__)
@@ -107,3 +110,20 @@ async def lenochka_reply(event: events.NewMessage.Event):
             ]
         )
     )
+
+
+@config.telegram_client.on(events.NewMessage(pattern="^.rl .*", forwards=False))
+@mark_unread
+async def run_rotations(event: events.NewMessage.Event):
+    text = event.message.message.lstrip(".rl").strip()
+    if text == "":
+        return
+    text_rotor = Rotor(text, 0)
+    start_rotation = datetime.now()
+    current_time = start_rotation
+    message = await event.respond(text)
+    while (current_time - start_rotation).seconds < 10:
+        await message.edit(text_rotor.next_rotation)
+        current_time = datetime.now()
+        await asyncio.sleep(0.2)
+    await message.delete()
diff --git a/src/utils/str_helpers.py b/src/utils/str_helpers.py
index 0d0c0dc..2da5106 100644
--- a/src/utils/str_helpers.py
+++ b/src/utils/str_helpers.py
@@ -7,14 +7,9 @@ class Rotor:
     ...
     """
 
-    original: str
-    start: int
-    stop: int
-
-    def __init__(self, original, start, stop):
+    def __init__(self, original, start):
         self.original = original
         self.start = start
-        self.stop = stop
         self.rotation = original + " "
 
     @property
diff --git a/static_messages/help.txt b/static_messages/help.txt
index 8a18520..1f6d008 100644
--- a/static_messages/help.txt
+++ b/static_messages/help.txt
@@ -14,6 +14,8 @@
 
 Также умею ещё пару забавных штук.
 `.sc` посмотреть поддерживаемые курсы валют для автоматической конвертации.
+`.scc` Посмотреть курсы криптовалют.
+`.rl` Создать бегущую строку из сообщения.
 `.i <запрос>` вернет пачку картинок с интернетиков.
 * `.bl` <любой текст> - заменит все запятые на всякие гадости.
 * `.t` - показать текущее время
-- 
GitLab