0% found this document useful (0 votes)
3 views2 pages

Mesage

Uploaded by

igor2020lolol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Mesage

Uploaded by

igor2020lolol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# meta developer: @yourname

# scope: hikka_only

from .. import loader, utils


import random
import asyncio

@loader.tds
class SglypaMod(loader.Module):
"""Сглыпа: повторяет случайные старые сообщения из чата"""

strings = {"name": "Sglypa"}

def __init__(self):
self.enabled_chats = set()
self.counters = {}
self.random_limits = {}
self.locks = {}

@loader.command()
async def sglypa(self, m):
"""
Вкл/выкл сглыпу в чате
"""
chat = m.chat_id
if chat in self.enabled_chats:
self.enabled_chats.remove(chat)
await m.edit("😴 Сглыпа выключена")
return

self.enabled_chats.add(chat)
self.counters[chat] = 0
self.random_limits[chat] = random.randint(2, 3)
self.locks[chat] = False
await m.edit("🌀 Сглыпа включена")

await self._send_random(m)

async def _send_random(self, m):


chat = m.chat_id
if chat not in self.enabled_chats:
return
if self.locks.get(chat, False):
return
self.locks[chat] = True

msg = await self._pick_random(m.client, chat, m.sender_id)


if not msg:
self.locks[chat] = False
return
try:
if getattr(msg, "message", None):
await m.client.send_message(chat, msg.message)
elif msg.media:
await m.client.send_message(chat, "📎", file=msg.media)
except Exception:
pass
self.locks[chat] = False
async def _pick_random(self, client, chat_id, my_id):
msgs = []
async for message in client.iter_messages(chat_id, limit=1000):
# игнорим свои и пустые
if message.sender_id == my_id:
continue
if getattr(message, "message", None) or message.media:
msgs.append(message)
if not msgs:
return None
return random.choice(msgs)

@loader.watcher()
async def watcher(self, m):
if not m.chat or m.sender_id is None:
return
chat = m.chat_id
if chat not in self.enabled_chats:
return
if m.sender_id == (await m.client.get_me()).id:
return

self.counters[chat] += 1
if self.counters[chat] >= self.random_limits[chat]:
self.counters[chat] = 0
self.random_limits[chat] = random.randint(2, 3)
if not self.locks.get(chat, False):
await self._send_random(m)

You might also like