-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnovoice.py
159 lines (132 loc) · 7.6 KB
/
novoice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Proprietary License Agreement
# Copyright (c) 2024-29 CodWiz
# Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software for personal and non-commercial purposes, subject to the following conditions:
# 1. The Software may not be modified, altered, or otherwise changed in any way without the explicit written permission of the author.
# 2. Redistribution of the Software, in original or modified form, is strictly prohibited without the explicit written permission of the author.
# 3. The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holder be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Software or the use or other dealings in the Software.
# 4. Any use of the Software must include the above copyright notice and this permission notice in all copies or substantial portions of the Software.
# 5. By using the Software, you agree to be bound by the terms and conditions of this license.
# For any inquiries or requests for permissions, please contact [email protected].
# ---------------------------------------------------------------------------------
# Name: NoVoice
# Description: A module for prohibiting the sending of voice and video messages
# Author: @hikka_mods
# ---------------------------------------------------------------------------------
# meta developer: @hikka_mods
# scope: NoVoice
# scope: NoVoice 0.0.1
# ---------------------------------------------------------------------------------
import logging
from telethon.tl.custom import Message
from .. import loader, utils
logger = logging.INFO(__name__)
@loader.tds
class NoVoiceMod(loader.Module):
"""A module for prohibiting the sending of voice and video messages"""
strings = {
"name": "NoVoice",
"novoice_true": "❌ Voice messages are disabled for all users!",
"novoice_false": "✅ Voice messages are allowed for all users again!",
"novoice_no_args": "Usage: .novoice [on/off]",
"novoiceuser_no_reply": "Usage: .novoiceuser [username/reply]",
"novoiceuser_true": "❌ User {user_id} is now forbidden to send voice messages!",
"novoicerm_no_reply": "Usage: .novoicerm [username/reply]",
"novoicerm_yes": "✅ User {user_id} is now allowed to send voice messages again!",
"novoicerm_no": "⚠️ User {user_id} not found in the banned list.",
"text": "❌ I do not accept voice messages!",
}
strings_ru = {
"novoice_true": "❌ Голосовые сообщения отключены для всех пользователей!",
"novoice_false": "✅ Голосовые сообщения снова разрешены для всех пользователей!",
"novoice_no_args": "Использование: .novoice [on/off]",
"novoiceuser_no_reply": "Использование: .novoiceuser [username/reply]",
"novoiceuser_true": "❌ Пользователю {user_id} запрещено отправлять голосовые сообщения!",
"novoicerm_no_reply": "Использование: .novoicerm [username/reply]",
"novoicerm_yes": "✅ Пользователю {user_id} снова разрешено отправлять голосовые сообщения!",
"novoicerm_no": "⚠ Пользователь {user_id} не найден в списке запрещенных.",
"text": "❌ Я не принимаю голосовые сообщения!",
}
async def client_ready(self, client, db):
self.client = client
self.db = db
self.novoice_global = self.db.get("NoVoice", "global", False)
self.banned_users = self.db.get("NoVoice", "banned_users", {})
@loader.command(
ru_doc="[on/off] — запрещает/разрешает всем пользователям отправку голосовых и видеосообщений.",
en_doc="[on/off] — prohibits/allows all users to send voice and video messages.",
)
async def novoice(self, message):
args = utils.get_args_raw(message)
if args == "on":
self.novoice_global = True
self.db.set("NoVoice", "global", self.novoice_global)
await utils.answer(message, self.strings("novoice_true"))
elif args == "off":
self.novoice_global = False
self.db.set("NoVoice", "global", self.novoice_global)
await utils.answer(message, self.strings("novoice_false"))
else:
await utils.answer(message, self.strings("novoice_no_args"))
@loader.command(
ru_doc="[username/reply] — запрещает пользователю отправку голосовых и видеосообщений.",
en_doc="[username/reply] — prohibits the user from sending voice and video messages.",
)
async def novoiceuser(self, message):
args = utils.get_args_raw(message)
reply = await message.get_reply_message()
if not args and not reply:
return await utils.answer(message, self.strings("novoiceuser_no_reply"))
if reply:
user_id = reply.from_id
else:
user = await self.client.get_entity(args)
user_id = user.id
self.banned_users[user_id] = True
self.db.set("NoVoice", "banned_users", self.banned_users)
await utils.answer(
message, self.strings("novoiceuser_true").format(user_id=user_id)
)
@loader.command(
ru_doc="[username/reply] — разрешает пользователю отправку голосовых и видеосообщений.",
en_doc="[username/reply] — allows the user to send voice and video messages.",
)
async def novoicerm(self, message):
args = utils.get_args_raw(message)
reply = await message.get_reply_message()
if not args and not reply:
return await utils.answer(message, self.strings("novoicerm_no_reply"))
user_id = None
if reply:
user_id = reply.sender_id
else:
try:
user = await self.client.get_entity(args)
user_id = user.id
except Exception as e:
logger.error(f"Failed to get entity for {args}: {e}")
if user_id in self.banned_users:
del self.banned_users[user_id]
self.db.set("NoVoice", "banned_users", self.banned_users)
await utils.answer(
message, self.strings("novoicerm_yes").format(user_id=user_id)
)
else:
await utils.answer(
message, self.strings("novoicerm_no").format(user_id=user_id)
)
async def watcher(self, message: Message):
"""Обрабатывает входящие сообщения"""
if (
isinstance(message, Message)
and not message.out
and message.is_private
and (self.novoice_global or message.sender_id in self.banned_users)
and (message.voice or message.video_note)
):
await message.delete()
await utils.answer(message, self.strings("text"))
logger.debug(
"Deleted voice/video message from user %s in chat %s",
message.sender_id,
message.chat_id,
)