# * _ __ __ _ _
# * / \ _ _ _ __ ___ _ __ __ _| \/ | ___ __| |_ _| | ___ ___
# * / _ \| | | | '__/ _ \| '__/ _` | |\/| |/ _ \ / _` | | | | |/ _ \/ __|
# * / ___ \ |_| | | | (_) | | | (_| | | | | (_) | (_| | |_| | | __/\__ \
# * /_/ \_\__,_|_| \___/|_| \__,_|_| |_|\___/ \__,_|\__,_|_|\___||___/
# *
# * © Copyright 2024
# *
# * https://t.me/AuroraModules
# *
# * 🔒 Code is licensed under GNU AGPLv3
# * 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# * ⛔️ You CANNOT edit this file without direct permission from the author.
# * ⛔️ You CANNOT distribute this file if you have modified it without the direct permission of the author.
# Name: WordFinder
# Author: Felix?
# Commands:
# .wfind
# scope: hikka_only
# meta developer: @AuroraModules
# meta pic: https://i.postimg.cc/Hx3Zm8rB/logo.png
# meta banner: https://te.legra.ph/file/c34c0a11aabd6a1fb6210.jpg
__version__ = (1, 0, 0)
from aiogram.types import Message as AiogramMessage
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from .. import loader, utils
@loader.tds
class WordFinderMod(loader.Module):
"""Universal module for searching for certain words in the text."""
strings = {
"name": "WordFinder",
"status_t": "ℹ️ Module status: Works",
"status_f": "ℹ️ Module status: Does not work",
"chat_id_error": "❗️ There is no value in the chat_id config or it is incorrect.",
"words_error": "❗️ There is no value in the words config or it is incorrect.",
"enabled": "✅ The module is enabled.",
"disabled": "✅ The module is disabled.",
"incorrect_args": "❌ Incorrect arguments have been entered.",
"message_found": "⚠ New message has been found ⚠\n\n{}\n\nThe found word: {}",
"": "",
"cfg_chat_id": "Enter the id of the chats or channels in which the words from the words config will be searched.",
"cfg_words": "Enter the words separated by commas that will be searched in the chats.",
"cfg_admin_chat_id": "Enter the chat id where notifications will be sent, if the value is None, the chat for notifications will be Word-Finder.",
}
strings_ru = {
"status_t": "ℹ️ Статус модуля: Работает",
"status_f": "ℹ️ Статус модуля: Не работает",
"chat_id_error": "❗️ В конфиге chat_id нет значения или оно неверное.",
"words_error": "❗️ В конфиге words нет значения или оно неверное.",
"enabled": "✅ Модуль включен.",
"disabled": "✅ Модуль отключен.",
"incorrect_args": "❌ Были введены неверные аргументы.",
"message_found": "⚠ Найдено новое сообщение ⚠\n\n{}\n\nНайденное слово: {}",
"cfg_chat_id": "Введите id чатов или каналов, в которых будут искаться слова из конфига words.",
"cfg_words": "Введите слова через запятую, которые будут искаться в чатах.",
"cfg_admin_chat_id": "Введите id чата, куда будут присылаться уведомления, если значение None, чатом для уведомлений будет Word-Finder.",
}
strings_uz = {
"status_t": "ℹ️ Modul holati: Faol",
"status_f": "ℹ️ Modul holati: Faol emas",
"chat_id_error": "❗️ Konfiguratsiyada chat_id qiymati mavjud emas yoki noto'g'ri.",
"words_error": "❗️ Konfiguratsiyada words qiymati mavjud emas yoki noto'g'ri.",
"enabled": "✅ Modul yoqildi.",
"disabled": "✅ Modul o'chirildi.",
"incorrect_args": "❌ Noto'g'ri argumentlar kiritildi.",
"message_found": "⚠ Yangi xabar topildi ⚠\n\n{}\n\nTopilgan so'z: {}",
"cfg_chat_id": "So'zlar izlanadigan chat yoki kanal idlarini kiriting.",
"cfg_words": "Chatlarda izlanadigan so'zlarni vergul bilan ajratib kiriting.",
"cfg_admin_chat_id": "Bildirishnomalar yuboriladigan chat idini kiriting. Agar None bo'lsa, Word-Finder bildirishnomalar uchun ishlatiladi.",
}
strings_de = {
"status_t": "ℹ️ Modulstatus: Aktiv",
"status_f": "ℹ️ Modulstatus: Inaktiv",
"chat_id_error": "❗️ Im Konfigurationswert chat_id fehlt oder ist ungültig.",
"words_error": "❗️ Im Konfigurationswert words fehlt oder ist ungültig.",
"enabled": "✅ Modul aktiviert.",
"disabled": "✅ Modul deaktiviert.",
"incorrect_args": "❌ Ungültige Argumente eingegeben.",
"message_found": "⚠ Neue Nachricht gefunden ⚠\n\n{}\n\nGefundenes Wort: {}",
"cfg_chat_id": "Geben Sie die IDs der Chats oder Kanäle ein, in denen nach Wörtern aus der Konfiguration gesucht werden soll.",
"cfg_words": "Geben Sie die zu suchenden Wörter in den Chats durch Kommas getrennt ein.",
"cfg_admin_chat_id": "Geben Sie die ID des Chats ein, in dem Benachrichtigungen gesendet werden sollen. Wenn None, wird Word-Finder für Benachrichtigungen verwendet.",
}
strings_es = {
"status_t": "ℹ️ Estado del módulo: Activo",
"status_f": "ℹ️ Estado del módulo: Inactivo",
"chat_id_error": "❗️ El valor de chat_id en la configuración no está presente o es incorrecto.",
"words_error": "❗️ El valor de words en la configuración no está presente o es incorrecto.",
"enabled": "✅ Módulo activado.",
"disabled": "✅ Módulo desactivado.",
"incorrect_args": "❌ Se ingresaron argumentos incorrectos.",
"message_found": "⚠ Se encontró un nuevo mensaje ⚠\n\n{}\n\nPalabra encontrada: {}",
"cfg_chat_id": "Ingrese las IDs de los chats o canales donde se buscarán las palabras de la configuración.",
"cfg_words": "Ingrese las palabras a buscar en los chats separadas por comas.",
"cfg_admin_chat_id": "Ingrese la ID del chat donde se enviarán las notificaciones. Si es None, se utilizará Word-Finder para las notificaciones.",
}
def __init__(self):
self.config = loader.ModuleConfig(
loader.ConfigValue(
"chat_id",
None,
lambda: self.strings("cfg_chat_id")
),
loader.ConfigValue(
"words",
[],
lambda: self.strings("cfg_words")
),
loader.ConfigValue(
"admin_chat_id",
None,
lambda: self.strings("cfg_admin_chat_id")
),
)
async def client_ready(self, client, db):
self.client = client
self.db = db
self.c, _ = await utils.asset_channel(
self.client,
"Word-Finder",
"Chat for receiving notifications about finding a word in the text.",
silent=True,
invite_bot=True,
)
self.chat = f"-100{self.c.id}"
@loader.command(
ru_doc=" - установить статус работы модуля",
uz_doc=" - o'rnatish modulining ish holati",
de_doc=" - den Betriebsstatus des Moduls festlegen",
es_doc=" - establecer el estado de funcionamiento del módulo",
)
async def wfind(self, message):
""" - set the module operation status"""
args = utils.get_args_raw(message).lower()
chat_id = self.config["chat_id"]
words = self.config["words"]
if not args:
if self.db.get("WordFinder", "status"):
status = self.strings("status_t")
else:
status = self.strings("status_f")
await utils.answer(message, status)
return
if chat_id == None:
await utils.answer(message, self.strings("chat_id_error"))
return
if words is None or words == []:
await utils.answer(message, self.strings("words_error"))
return
if args == "on":
self.db.set("WordFinder", "status", True)
await utils.answer(message, self.strings("enabled"))
return
elif args == "off":
self.db.set("WordFinder", "status", False)
await utils.answer(message, self.strings("disabled"))
return
else:
await utils.answer(message, self.strings("incorrect_args"))
return
async def watcher(self, message: AiogramMessage):
if not self.db.get("WordFinder", "status", False):
return
chat_id = self.config["chat_id"]
words = self.config["words"]
admin_chat_id = self.config["admin_chat_id"]
if isinstance(chat_id, int):
chat_ids = [chat_id]
elif isinstance(chat_id, list):
chat_ids = chat_id
else:
return
if isinstance(words, str):
words = [word.strip() for word in words.split(',')]
if message.chat_id not in chat_ids:
return
if not message.text:
return
if any(word in message.text.lower().split() for word in words):
found_words = [word for word in words if word in message.text.lower()]
if found_words:
found_word = ', '.join(found_words)
if message.is_private:
message_url = f"tg://openmessage?user_id={message.chat_id}"
else:
message_url = f"https://t.me/c/{message.chat.id}/{message.id}"
if self.config["admin_chat_id"] == None:
reply_markup = InlineKeyboardMarkup()
reply_markup.add(InlineKeyboardButton(text="🔗 Link", url=message_url))
await self.inline.bot.send_message(
self.chat,
self.strings("message_found").format(message.text, found_word),
reply_markup=reply_markup
)
else:
await self.inline.form(
message=admin_chat_id,
text=self.strings("message_found").format(message.text, found_word),
reply_markup=[
[
{"text": "🔗 Link", "url": message_url}
],
],
)