# * _ __ __ _ _
# * / \ _ _ _ __ ___ _ __ __ _| \/ | ___ __| |_ _| | ___ ___
# * / _ \| | | | '__/ _ \| '__/ _` | |\/| |/ _ \ / _` | | | | |/ _ \/ __|
# * / ___ \ |_| | | | (_) | | | (_| | | | | (_) | (_| | |_| | | __/\__ \
# * /_/ \_\__,_|_| \___/|_| \__,_|_| |_|\___/ \__,_|\__,_|_|\___||___/
# *
# * © 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: AuroraAFK
# Author: dend1yy | Felix?
# Commands:
# .afk | .removestatus | .setstatus | .unafk
# scope: hikka_only
# meta developer: @AuroraModules
# meta pic: https://i.postimg.cc/Hx3Zm8rB/logo.png
# meta banner: https://te.legra.ph/file/f35de08579b3bd2235bc4.jpg
__version__ = (1, 0, 3)
import datetime
import logging
import time
from telethon import types, functions # type: ignore
from .. import loader, utils
logger = logging.getLogger(__name__)
@loader.tds
class AuroraAFKMod(loader.Module):
"""Your personal assistant to while you are in AFK mode"""
strings = {
"name": "AuroraAFK",
"gone": "✅ You have successfully entered AFK mode!",
"back": "✅ You have successfully exited AFK mode!",
"afk": "😴 I'm currently in AFK\n🌀 Was online {} ago",
"afk_reason": "😴 I'm currently in AFK\n🌀 Was online {} ago\n✏️ Reason: {}",
"status_added": "🦋 Status successfully set!",
"status_removed": "🗑 Status successfully removed!",
"no_user": "❌ Failed to get user information.",
"no_previous_status": "😵💫 Previous nickname not found.",
}
strings_ru = {
"gone": "✅ Вы успешно вошли в AFK режим!",
"back": "✅ Вы успешно вышли из AFK режима!",
"afk": "😴 Сейчас я нахожусь в AFK\n🌀 Был в сети {} назад",
"afk_reason": "😴 Сейчас я нахожусь в AFK\n🌀 Был в сети {} назад\n✏️ Причина: {}",
"status_added": "🦋 Статус успешно установлен!",
"status_removed": "🗑 Статус успешно удалён!",
"no_user": "❌ Не удалось получить информацию о пользователе.",
"no_previous_status": "😵💫 Предыдущий ник не найден.",
}
strings_uz = {
"gone": "✅ AFK holatiga muvaffaqiyatli kirdingiz!",
"back": "✅ AFK rejimidan muvaffaqiyatli chiqdingiz!",
"afk": "😴 Hozir men AFK holatida\n🌀 {} avval onlayn bo'lgan",
"afk_reason": "😴 Hozir men AFK holatida\n🌀 {} avval onlayn bo'lgan\n✏️ Sabab: {}",
"status_added": "🦋 Status muvaffaqiyatli o'rnatildi!",
"status_removed": "🗑 Status muvaffaqiyatli olib tashlandi!",
"no_user": "❌ Foydalanuvchi ma'lumotlari olishda xatolik.",
"no_previous_status": "😵💫 Avvalgi nom topilmadi.",
}
strings_de = {
"gone": "✅ Du hast den AFK-Modus erfolgreich aktiviert!",
"back": "✅ Du hast den AFK-Modus erfolgreich deaktiviert!",
"afk": "😴 Ich bin derzeit im AFK\n🌀 War vor {} online",
"afk_reason": "😴 Ich bin derzeit im AFK\n🌀 War vor {} online\n✏️ Grund: {}",
"status_added": "🦋 Status erfolgreich gesetzt!",
"status_removed": "🗑 Status erfolgreich entfernt!",
"no_user": "❌ Benutzerinformationen konnten nicht abgerufen werden.",
"no_previous_status": "😵💫 Vorheriger Spitzname nicht gefunden.",
}
strings_es = {
"gone": "✅ ¡Has entrado correctamente en el modo AFK!",
"back": "✅ ¡Has salido correctamente del modo AFK!",
"afk": "😴 Actualmente estoy en AFK\n🌀 Estuve en línea hace {}",
"afk_reason": "😴 Actualmente estoy en AFK\n🌀 Estuve en línea hace {}\n✏️ Razón: {}",
"status_added": "🦋 ¡Estado establecido correctamente!",
"status_removed": "🗑 ¡Estado eliminado correctamente!",
"no_user": "❌ No se pudieron obtener las información del usuario.",
"no_previous_status": "😵💫 Nombre de usuario anterior no encontrado.",
}
async def client_ready(self, client, db):
self.client = client
self._db = db
self._me = await client.get_me()
@loader.command(
ru_doc="[reason] - Установить режим AFK",
uz_doc="[reason] - AFK holatini sozlash",
de_doc="[reason] - AFK-Modusstatus setzen",
es_doc="[reason] - Establecer estado de modo AFK"
)
async def afk(self, message):
"""[reason] - Set AFK mode status"""
if utils.get_args_raw(message):
self._db.set(__name__, "afk", utils.get_args_raw(message))
else:
self._db.set(__name__, "afk", True)
self._db.set(__name__, "gone", time.time())
self._db.set(__name__, "ratelimit", [])
await self.allmodules.log("afk", data=utils.get_args_raw(message) or None)
await utils.answer(message, self.strings("gone", message))
@loader.command(
ru_doc="Выйти из режима AFK",
uz_doc="AFK rejimidan chiqish",
de_doc="Verlassen des AFK-Modus",
es_doc="Salir del modo AFK"
)
async def unafk(self, message):
"""Exit AFK mode"""
self._db.set(__name__, "afk", False)
self._db.set(__name__, "gone", None)
self._db.set(__name__, "ratelimit", [])
await self.allmodules.log("unafk")
await utils.answer(message, self.strings("back", message))
@loader.command(
ru_doc="Установить статус AFK",
uz_doc="AFK holatini sozlash",
de_doc="Setzt den AFK-Status",
es_doc="Establece el estado AFK"
)
async def setstatus(self, message):
"""Set the AFK status"""
user = await utils.get_user(message)
if user:
current_last_name = user.last_name if user.last_name else ""
if " || AFK" in current_last_name:
await utils.answer(message, self.strings["status_added"].format(name=current_last_name))
return
new_last_name = current_last_name + " || AFK"
try:
await self.client(functions.account.UpdateProfileRequest(last_name=new_last_name))
await utils.answer(message, self.strings["status_added"].format(name=new_last_name))
except Exception as e:
await utils.answer(message, f"Ошибка при добавлении статуса: {str(e)}")
else:
await utils.answer(message, self.strings["no_user"])
@loader.command(
ru_doc="Удалить статус AFK",
uz_doc="AFK holatini o'chirish",
de_doc="Löscht den AFK-Status",
es_doc="Eliminar el estado AFK"
)
async def removestatus(self, message):
"""Удалить статус AFK."""
user = await utils.get_user(message)
if user:
current_last_name = user.last_name if user.last_name else ""
if " || AFK" in current_last_name:
try:
previous_first_name = user.first_name if user.first_name else ""
previous_last_name = current_last_name.replace(" || AFK", "")
await self.client(functions.account.UpdateProfileRequest(first_name=previous_first_name, last_name=previous_last_name))
await utils.answer(message, self.strings["status_removed"])
except Exception as e:
await utils.answer(message, f"Ошибка при удалении статуса: {str(e)}")
else:
await utils.answer(message, self.strings["no_previous_status"])
else:
await utils.answer(message, self.strings["no_user"])
async def watcher(self, message):
if not isinstance(message, types.Message):
return
if message.mentioned or getattr(message.to_id, "user_id", None) == self._me.id:
afk_state = self.get_afk()
if not afk_state:
return
logger.debug("tagged!")
ratelimit = self._db.get(__name__, "ratelimit", [])
if utils.get_chat_id(message) in ratelimit:
return
else:
self._db.setdefault(__name__, {}).setdefault("ratelimit", []).append(
utils.get_chat_id(message)
)
self._db.save()
user = await utils.get_user(message)
if user.is_self or user.bot or user.verified:
logger.debug("User is self, bot or verified.")
return
if self.get_afk() is False:
return
now = datetime.datetime.now().replace(microsecond=0)
gone = datetime.datetime.fromtimestamp(
self._db.get(__name__, "gone")
).replace(microsecond=0)
diff = now - gone
if afk_state is True:
ret = self.strings("afk", message).format(diff)
elif afk_state is not False:
ret = self.strings("afk_reason", message).format(diff, afk_state)
await utils.answer(message, ret, reply_to=message)
def get_afk(self):
return self._db.get(__name__, "afk", False)