Files
limoka/Den4ikSuperOstryyPer4ik/Astro-modules/Emotions.py
2025-07-10 21:02:34 +03:00

183 lines
6.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

__version__ = (1, 0, 1)
#
# @@@@@@ @@@@@@ @@@@@@@ @@@@@@@ @@@@@@ @@@@@@@@@@ @@@@@@ @@@@@@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@
# @@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@@
# @@! @@@ !@@ @@! @@! @@@ @@! @@@ @@! @@! @@! @@! @@@ @@! @@@ @@! @@@ @@! @@! !@@
# !@! @!@ !@! !@! !@! @!@ !@! @!@ !@! !@! !@! !@! @!@ !@! @!@ !@! @!@ !@! !@! !@!
# @!@!@!@! !!@@!! @!! @!@!!@! @!@ !@! @!! !!@ @!@ @!@ !@! @!@ !@! @!@ !@! @!! @!!!:! !!@@!!
# !!!@!!!! !!@!!! !!! !!@!@! !@! !!! !@! ! !@! !@! !!! !@! !!! !@! !!! !!! !!!!!: !!@!!!
# !!: !!! !:! !!: !!: :!! !!: !!! !!: !!: !!: !!! !!: !!! !!: !!! !!: !!: !:!
# :!: !:! !:! :!: :!: !:! :!: !:! :!: :!: :!: !:! :!: !:! :!: !:! :!: :!: !:!
# :: ::: :::: :: :: :: ::: ::::: :: ::: :: ::::: :: :::: :: ::::: :: :: :::: :: :::: :::: ::
# : : : :: : : : : : : : : : : : : : : :: : : : : : : :: : : : :: :: :: : :
#
# © Copyright 2024
#
# https://t.me/Den4ikSuperOstryyPer4ik
# and
# https://t.me/ToXicUse
#
# 🔒 Licensed under the GNU AGPLv3
# https://www.gnu.org/licenses/agpl-3.0.html
#
# meta developer: @AstroModules, @HikariMods
# meta banner: https://raw.githubusercontent.com/Den4ikSuperOstryyPer4ik/Astro-modules/main/Banners/Emotions.jpg
import grapheme
from telethon.tl.types import Message
from .. import loader, utils
@loader.tds
class EmotionsMod(loader.Module):
'''Выражение эмоций в чате'''
strings = {
"name": "Emotions",
'delete_msg': "Удалять сообщение которое вызывает эмоцию?",
'on': "<emoji document_id=5373230475022179039>🥺</emoji> Emotions успешно активирован в этом чате.",
'off': "<emoji document_id=5373230475022179039>🥺</emoji> Emotions успешно деактивирован в этом чате",
'ok': "<emoji document_id=5188315103384050849>☑️</emoji>Эмоция успешно добавлена",
'list': "<emoji document_id=5373230475022179039>🥺</emoji> Доступные эмоции:\n\n{}\n\n<emoji document_id=5467928559664242360>❗️</emoji> Для добавления своих эмоций введите команду:\n <code>.emo</code> <символ/слово> <эмоция>",
}
async def client_ready(self):
self.emo = self.get(
"emo",
{
')': '😊 улыбается',
'(': '🙁 грустит',
'😭': '😭 плачет',
'😃': "😃 радуется",
"😏": "😏 думает о кое-чем)))",
"🤔": "🤔 призадумался",
"😂": "😂 смеется",
"🤣": "🤣 ржет",
"😞": "😞 расстроен",
"😔": "😔 сильно расстроен",
"😍": "😍 что-то нравится",
"😤": "😤 зол",
"😡": "😡 сильно зол",
"🤬": "🤬 матерится",
"😎": "😎 типа крутой",
"😳": "😳 шокирован",
"🤢": "🤢 думает что это противно",
"🫠": "🫠 весь течет",
"🥺": "🥺 считает что это мило",
},
)
self.chats = self.get("active", [])
def __init__(self):
self.config = loader.ModuleConfig(
loader.ConfigValue(
'delete',
True,
doc=lambda: self.strings("delete_msg"),
validator=loader.validators.Boolean()
)
)
async def emogocmd(self, message: Message):
"""- вкл/выкл эмоции в данном чате"""
cid = str(utils.get_chat_id(message))
if cid in self.chats:
self.chats.remove(cid)
await utils.answer(message, self.strings("off"))
else:
self.chats += [cid]
await utils.answer(message, self.strings("on"))
self.set("active", self.chats)
async def emoclearcmd(self, message: Message):
"""<y> - сбросить список эмоций"""
args = utils.get_args_raw(message)
if args == "y":
await self.allmodules.commands["e"](
await utils.answer(message, f"{self.get_prefix()}e db.pop('EmotionsMod')")
)
await utils.answer(message, "<emoji document_id=5370842086658546991>☠️</emoji> <b>Список эмоций успешно сброшен до зоводских настроек\nПожалуйста, загрузите модуль еще раз.</b>")
else:
await utils.answer(message, '<emoji document_id=5370842086658546991>☠️</emoji> <b>Вы не подтвердили удаление!</b>')
async def emolistcmd(self, message: Message):
"""- список доступных эмоций"""
await utils.answer(
message,
self.strings("list").format(
"\n".join(
[f" ▪️ {simvol} - {emotion}" for simvol, emotion in self.emo.items()]
)
),
)
async def emocmd(self, message: Message):
"""<символ|слово> <эмоция> - добавить эмоцию в базу модуля"""
args = utils.get_args_raw(message)
try:
simvol = args.split(" ", 1)[0]
emotion = args.split(" ", 1)[1]
except Exception:
if not args or simvol not in self.emo:
await utils.answer(message, '<emoji document_id=5467928559664242360>❗️</emoji> Вы ввели неверное значение. Попробуйте снова')
else:
del self.emo[simvol]
self.set("emo", self.emo)
await utils.answer(message, self.strings("ok"))
return
self.emo[simvol] = emotion
self.set("emo", self.emo)
await utils.answer(message, self.strings("ok"))
async def watcher(self, message: Message):
cid = str(utils.get_chat_id(message))
try:
if (
cid not in self.chats
or not isinstance(message, Message)
or not hasattr(message, "raw_text")
or message.raw_text.split(maxsplit=1)[0].lower() not in self.emo
):
return
except IndexError:
return
try:
cmd = message.raw_text.split(maxsplit=1)[0].lower()
except IndexError:
return
msg = self.emo[cmd]
sender = await self._client.get_entity(message.sender_id)
if utils.emoji_pattern.match(next(grapheme.graphemes(msg))):
msg = list(grapheme.graphemes(msg))
emoji = msg[0]
msg = "".join(msg[1:])
else:
emoji = "<emoji document_id=5373230475022179039>🥺</emoji>"
if self.config['delete']:
if message.out:
pass
else:
await message.delete()
await utils.answer(
message,
f'{emoji} <a href="tg://user?id={sender.id}">{utils.escape_html(sender.first_name)}</a> <b>{utils.escape_html(msg)}</b> {emoji}')