iamgojoof6eyes commited on
Commit
1e7cb23
·
1 Parent(s): 50616b2
Powers/plugins/admin.py CHANGED
@@ -19,6 +19,7 @@ from Powers.bot_class import Gojo
19
  from Powers.database.approve_db import Approve
20
  from Powers.database.reporting_db import Reporting
21
  from Powers.utils.caching import ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK, admin_cache_reload
 
22
  from Powers.utils.custom_filters import (
23
  DEV_LEVEL,
24
  admin_filter,
@@ -34,7 +35,8 @@ from Powers.vars import Config
34
  @Gojo.on_message(command("adminlist"))
35
  async def adminlist_show(_, m: Message):
36
  global ADMIN_CACHE
37
- if m.chat.type != "supergroup":
 
38
  return await m.reply_text(
39
  text="This command is made to be used in groups only!",
40
  )
@@ -120,8 +122,8 @@ async def zombie_clean(c: Gojo, m: Message):
120
  @Gojo.on_message(command("admincache"))
121
  async def reload_admins(_, m: Message):
122
  global TEMP_ADMIN_CACHE_BLOCK
123
-
124
- if m.chat.type != "supergroup":
125
  return await m.reply_text(
126
  "This command is made to be used in groups only!",
127
  )
 
19
  from Powers.database.approve_db import Approve
20
  from Powers.database.reporting_db import Reporting
21
  from Powers.utils.caching import ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK, admin_cache_reload
22
+ from Powers.utils.chat_type import chattype
23
  from Powers.utils.custom_filters import (
24
  DEV_LEVEL,
25
  admin_filter,
 
35
  @Gojo.on_message(command("adminlist"))
36
  async def adminlist_show(_, m: Message):
37
  global ADMIN_CACHE
38
+ chat_type = chattype(_, m)
39
+ if chat_type != "supergroup" or chat_type != "group":
40
  return await m.reply_text(
41
  text="This command is made to be used in groups only!",
42
  )
 
122
  @Gojo.on_message(command("admincache"))
123
  async def reload_admins(_, m: Message):
124
  global TEMP_ADMIN_CACHE_BLOCK
125
+ chat_type = chattype(_, m)
126
+ if chat_type != "supergroup" or chat_type != "group":
127
  return await m.reply_text(
128
  "This command is made to be used in groups only!",
129
  )
Powers/plugins/greetings.py CHANGED
@@ -10,6 +10,7 @@ from Powers.bot_class import Gojo
10
  from Powers.database.antispam_db import GBan
11
  from Powers.database.greetings_db import Greetings
12
  from Powers.utils.custom_filters import admin_filter, bot_admin_filter, command
 
13
  from Powers.utils.msg_types import Types, get_wlcm_type
14
  from Powers.utils.parser import escape_markdown, mention_html
15
  from Powers.utils.string import (
@@ -53,7 +54,8 @@ async def escape_mentions_using_curly_brackets_wl(
53
  ),
54
  mention=await (mention_html(escape(user.first_name), user.id)),
55
  chatname=escape(m.chat.title)
56
- if m.chat.type != "private"
 
57
  else escape(user.first_name),
58
  id=user.id,
59
  )
 
10
  from Powers.database.antispam_db import GBan
11
  from Powers.database.greetings_db import Greetings
12
  from Powers.utils.custom_filters import admin_filter, bot_admin_filter, command
13
+ from Powers.utils.chat_type import chattype
14
  from Powers.utils.msg_types import Types, get_wlcm_type
15
  from Powers.utils.parser import escape_markdown, mention_html
16
  from Powers.utils.string import (
 
54
  ),
55
  mention=await (mention_html(escape(user.first_name), user.id)),
56
  chatname=escape(m.chat.title)
57
+ chat_type = chattype(_, m)
58
+ if chat_type != "private"
59
  else escape(user.first_name),
60
  id=user.id,
61
  )
Powers/plugins/purge.py CHANGED
@@ -5,12 +5,14 @@ from pyrogram.types import Message
5
 
6
  from Powers import SUPPORT_GROUP
7
  from Powers.bot_class import Gojo
 
8
  from Powers.utils.custom_filters import admin_filter, command
9
 
10
 
11
  @Gojo.on_message(command("purge") & admin_filter)
12
  async def purge(c: Gojo, m: Message):
13
- if m.chat.type != "supergroup":
 
14
  await m.reply_text(text="Cannot purge messages in a basic group")
15
  return
16
 
@@ -57,7 +59,8 @@ async def purge(c: Gojo, m: Message):
57
 
58
  @Gojo.on_message(command("spurge") & admin_filter)
59
  async def spurge(c: Gojo, m: Message):
60
- if m.chat.type != "supergroup":
 
61
  await m.reply_text(text="Cannot purge messages in a basic group")
62
  return
63
 
@@ -98,7 +101,8 @@ async def spurge(c: Gojo, m: Message):
98
  group=9,
99
  )
100
  async def del_msg(c: Gojo, m: Message):
101
- if m.chat.type != "supergroup":
 
102
  return
103
 
104
  if m.reply_to_message:
 
5
 
6
  from Powers import SUPPORT_GROUP
7
  from Powers.bot_class import Gojo
8
+ from Powers.utils.chat_type import chattype
9
  from Powers.utils.custom_filters import admin_filter, command
10
 
11
 
12
  @Gojo.on_message(command("purge") & admin_filter)
13
  async def purge(c: Gojo, m: Message):
14
+ chat_type = chattype(_,m)
15
+ if chat_type != "supergroup" or chat_type != "group":
16
  await m.reply_text(text="Cannot purge messages in a basic group")
17
  return
18
 
 
59
 
60
  @Gojo.on_message(command("spurge") & admin_filter)
61
  async def spurge(c: Gojo, m: Message):
62
+ chat_type = chattype(_,m)
63
+ if chat_type != "supergroup" or chat_type != "group":
64
  await m.reply_text(text="Cannot purge messages in a basic group")
65
  return
66
 
 
101
  group=9,
102
  )
103
  async def del_msg(c: Gojo, m: Message):
104
+ chat_type = chattype(_,m)
105
+ if chat_type != "supergroup" or chat_type != "group":
106
  return
107
 
108
  if m.reply_to_message:
Powers/plugins/report.py CHANGED
@@ -9,6 +9,7 @@ from Powers.bot_class import Gojo
9
  from Powers.database.reporting_db import Reporting
10
  from Powers.utils.custom_filters import admin_filter, command
11
  from Powers.utils.kbhelpers import ikb
 
12
  from Powers.utils.parser import mention_html
13
 
14
 
@@ -19,7 +20,8 @@ async def report_setting(_, m: Message):
19
  args = m.text.split()
20
  db = Reporting(m.chat.id)
21
 
22
- if m.chat.type == "private":
 
23
  if len(args) >= 2:
24
  option = args[1].lower()
25
  if option in ("yes", "on", "true"):
@@ -63,7 +65,8 @@ async def report_setting(_, m: Message):
63
 
64
  @Gojo.on_message(command("report") & filters.group)
65
  async def report_watcher(c: Gojo, m: Message):
66
- if m.chat.type != "supergroup":
 
67
  return
68
 
69
  if not m.from_user:
 
9
  from Powers.database.reporting_db import Reporting
10
  from Powers.utils.custom_filters import admin_filter, command
11
  from Powers.utils.kbhelpers import ikb
12
+ from Powers.utils.chat_type import chattype
13
  from Powers.utils.parser import mention_html
14
 
15
 
 
20
  args = m.text.split()
21
  db = Reporting(m.chat.id)
22
 
23
+ chat_type = chattype(_,m)
24
+ if chat_type == "private":
25
  if len(args) >= 2:
26
  option = args[1].lower()
27
  if option in ("yes", "on", "true"):
 
65
 
66
  @Gojo.on_message(command("report") & filters.group)
67
  async def report_watcher(c: Gojo, m: Message):
68
+ chat_type = chattype(_,m)
69
+ if chat_type != "supergroup" or chat_type != "group":
70
  return
71
 
72
  if not m.from_user:
Powers/plugins/start.py CHANGED
@@ -6,6 +6,7 @@ from Powers import HELP_COMMANDS, LOGGER
6
  from Powers.bot_class import Gojo
7
  from Powers.utils.custom_filters import command
8
  from Powers.utils.kbhelpers import ikb
 
9
  from Powers.utils.start_utils import (
10
  gen_cmds_kb,
11
  gen_start_kb,
 
6
  from Powers.bot_class import Gojo
7
  from Powers.utils.custom_filters import command
8
  from Powers.utils.kbhelpers import ikb
9
+ from Powers.utils.chat_type import chattype
10
  from Powers.utils.start_utils import (
11
  gen_cmds_kb,
12
  gen_start_kb,
Powers/plugins/utils.py CHANGED
@@ -22,6 +22,7 @@ from Powers.database.antispam_db import GBan
22
  from Powers.database.users_db import Users
23
  from Powers.utils.clean_file import remove_markdown_and_html
24
  from Powers.utils.custom_filters import command
 
25
  from Powers.utils.http_helper import *
26
  from Powers.utils.kbhelpers import ikb
27
  from Powers.utils.parser import mention_html
@@ -130,11 +131,12 @@ async def get_lyrics(_, m: Message):
130
  )
131
  async def id_info(c: Gojo, m: Message):
132
 
133
- if m.chat.type == "supergroup" and not m.reply_to_message:
 
134
  await m.reply_text(text=f"This Group's ID is <code>{m.chat.id}</code>")
135
  return
136
 
137
- if m.chat.type == "private" and not m.reply_to_message:
138
  await m.reply_text(text=f"Your ID is <code>{m.chat.id}</code>.")
139
  return
140
 
@@ -164,7 +166,7 @@ async def id_info(c: Gojo, m: Message):
164
  f"{(await mention_html(user.first_name, user.id))}'s ID is <code>{user.id}</code>.",
165
  parse_mode="HTML",
166
  )
167
- elif m.chat.type == "private":
168
  await m.reply_text(
169
  text=f"Your ID is <code>{m.chat.id}</code>."
170
  )
 
22
  from Powers.database.users_db import Users
23
  from Powers.utils.clean_file import remove_markdown_and_html
24
  from Powers.utils.custom_filters import command
25
+ from Powers.utils.chat_type import chattype
26
  from Powers.utils.http_helper import *
27
  from Powers.utils.kbhelpers import ikb
28
  from Powers.utils.parser import mention_html
 
131
  )
132
  async def id_info(c: Gojo, m: Message):
133
 
134
+ chat_type = chattype(_,m)
135
+ if chat_type == "supergroup" or chat_type == "group" and not m.reply_to_message:
136
  await m.reply_text(text=f"This Group's ID is <code>{m.chat.id}</code>")
137
  return
138
 
139
+ if chat_type == "private" and not m.reply_to_message:
140
  await m.reply_text(text=f"Your ID is <code>{m.chat.id}</code>.")
141
  return
142
 
 
166
  f"{(await mention_html(user.first_name, user.id))}'s ID is <code>{user.id}</code>.",
167
  parse_mode="HTML",
168
  )
169
+ elif chat_type == "private":
170
  await m.reply_text(
171
  text=f"Your ID is <code>{m.chat.id}</code>."
172
  )
Powers/utils/chat_type.py CHANGED
@@ -1 +1,23 @@
1
- from pyrogram import enums
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import enum
2
+ from pyrogram.enums import ChatType
3
+ from pyrogram.types import Message
4
+
5
+
6
+ async def chattype(_, m: Message):
7
+ if bool(m.chat and m.chat.type in {ChatType.CHANNEL}):
8
+ ct = "channel"
9
+
10
+ if bool(m.chat and m.chat.type in {ChatType.PRIVATE}):
11
+ ct = "private"
12
+
13
+ if bool(m.chat and m.chat.type in {ChatType.GROUP}):
14
+ ct = "group"
15
+
16
+ if bool(m.chat and m.chat.type in {ChatType.SUPERGROUP}):
17
+ ct = "supergroup"
18
+
19
+ if bool(m.chat and m.chat.type in {ChatType.BOT}):
20
+ ct ="bot"
21
+
22
+
23
+ return ct
Powers/utils/custom_filters.py CHANGED
@@ -12,6 +12,7 @@ from pyrogram import enums
12
  from Powers import DEV_USERS, OWNER_ID, SUDO_USERS
13
  from Powers.database.disable_db import Disabling
14
  from Powers.utils.caching import ADMIN_CACHE, admin_cache_reload
 
15
  from Powers.vars import Config
16
 
17
  SUDO_LEVEL = set(SUDO_USERS + DEV_USERS + [int(OWNER_ID)])
@@ -70,7 +71,7 @@ def command(
70
  m.command = [matches.group(1)]
71
  if matches.group(1) not in flt.commands:
72
  return False
73
- if m.chat.type == "supergroup":
74
  try:
75
  user_status = (await m.chat.get_member(m.from_user.id)).status
76
  except UserNotParticipant:
@@ -117,7 +118,8 @@ async def bot_admin_check_func(_, __, m: Message or CallbackQuery):
117
  if isinstance(m, CallbackQuery):
118
  m = m.message
119
 
120
- if m.chat.type != "supergroup":
 
121
  return False
122
 
123
  # Telegram and GroupAnonyamousBot
@@ -150,7 +152,8 @@ async def admin_check_func(_, __, m: Message or CallbackQuery):
150
  if isinstance(m, CallbackQuery):
151
  m = m.message
152
 
153
- if m.chat.type != "supergroup":
 
154
  return False
155
 
156
  # Telegram and GroupAnonyamousBot
@@ -185,7 +188,7 @@ async def owner_check_func(_, __, m: Message or CallbackQuery):
185
  if isinstance(m, CallbackQuery):
186
  m = m.message
187
 
188
- if m.chat.type != "supergroup":
189
  return False
190
 
191
  # Bypass the bot devs, sudos and owner
@@ -212,7 +215,8 @@ async def restrict_check_func(_, __, m: Message or CallbackQuery):
212
  if isinstance(m, CallbackQuery):
213
  m = m.message
214
 
215
- if m.chat.type != "supergroup":
 
216
  return False
217
 
218
  # Bypass the bot devs, sudos and owner
@@ -235,7 +239,7 @@ async def promote_check_func(_, __, m):
235
  if isinstance(m, CallbackQuery):
236
  m = m.message
237
 
238
- if m.chat.type != "supergroup":
239
  return False
240
 
241
  # Bypass the bot devs, sudos and owner
@@ -258,7 +262,8 @@ async def changeinfo_check_func(_, __, m):
258
  if isinstance(m, CallbackQuery):
259
  m = m.message
260
 
261
- if m.chat.type != "supergroup":
 
262
  await m.reply_text("This command is made to be used in groups not in pm!")
263
  return False
264
 
@@ -286,7 +291,7 @@ async def can_pin_message_func(_, __, m):
286
  if isinstance(m, CallbackQuery):
287
  m = m.message
288
 
289
- if m.chat.type != "supergroup":
290
  await m.reply_text("This command is made to be used in groups not in pm!")
291
  return False
292
 
 
12
  from Powers import DEV_USERS, OWNER_ID, SUDO_USERS
13
  from Powers.database.disable_db import Disabling
14
  from Powers.utils.caching import ADMIN_CACHE, admin_cache_reload
15
+ from Powers.utils.chat_type import chattype
16
  from Powers.vars import Config
17
 
18
  SUDO_LEVEL = set(SUDO_USERS + DEV_USERS + [int(OWNER_ID)])
 
71
  m.command = [matches.group(1)]
72
  if matches.group(1) not in flt.commands:
73
  return False
74
+ if bool(m.chat and m.chat.type in {enums.ChatType.SUPERGROUP}):
75
  try:
76
  user_status = (await m.chat.get_member(m.from_user.id)).status
77
  except UserNotParticipant:
 
118
  if isinstance(m, CallbackQuery):
119
  m = m.message
120
 
121
+ chat_type = chattype(_,m)
122
+ if chat_type != "supergroup" or chat_type != "group":
123
  return False
124
 
125
  # Telegram and GroupAnonyamousBot
 
152
  if isinstance(m, CallbackQuery):
153
  m = m.message
154
 
155
+ chat_type = chattype(_,m)
156
+ if chat_type != "supergroup" or chat_type != "group":
157
  return False
158
 
159
  # Telegram and GroupAnonyamousBot
 
188
  if isinstance(m, CallbackQuery):
189
  m = m.message
190
 
191
+ if bool(m.chat and m.chat.type in {enums.ChatType.SUPERGROUP}):
192
  return False
193
 
194
  # Bypass the bot devs, sudos and owner
 
215
  if isinstance(m, CallbackQuery):
216
  m = m.message
217
 
218
+ chat_type = chattype(_,m)
219
+ if chat_type != "supergroup" or chat_type != "group":
220
  return False
221
 
222
  # Bypass the bot devs, sudos and owner
 
239
  if isinstance(m, CallbackQuery):
240
  m = m.message
241
 
242
+ if bool(m.chat and m.chat.type in {enums.ChatType.SUPERGROUP}):
243
  return False
244
 
245
  # Bypass the bot devs, sudos and owner
 
262
  if isinstance(m, CallbackQuery):
263
  m = m.message
264
 
265
+ chat_type = chattype(_,m)
266
+ if chat_type != "supergroup" or chat_type != "group":
267
  await m.reply_text("This command is made to be used in groups not in pm!")
268
  return False
269
 
 
291
  if isinstance(m, CallbackQuery):
292
  m = m.message
293
 
294
+ if not bool(m.chat and m.chat.type in {enums.ChatType.SUPERGROUP}):
295
  await m.reply_text("This command is made to be used in groups not in pm!")
296
  return False
297
 
Powers/utils/string.py CHANGED
@@ -6,6 +6,7 @@ from typing import List
6
  from pyrogram.types import InlineKeyboardButton, Message
7
 
8
  from Powers.utils.parser import escape_markdown
 
9
 
10
  BTN_URL_REGEX = compile_re(r"(\[([^\[]+?)\]\(buttonurl:(?:/{0,2})(.+?)(:same)?\))")
11
 
@@ -141,7 +142,8 @@ async def escape_mentions_using_curly_brackets(
141
  else [escape(m.from_user.first_name)],
142
  ),
143
  chatname=escape(m.chat.title)
144
- if m.chat.type != "private"
 
145
  else escape(m.from_user.first_name),
146
  id=m.from_user.id,
147
  )
 
6
  from pyrogram.types import InlineKeyboardButton, Message
7
 
8
  from Powers.utils.parser import escape_markdown
9
+ from Powers.utils.chat_type import chattype
10
 
11
  BTN_URL_REGEX = compile_re(r"(\[([^\[]+?)\]\(buttonurl:(?:/{0,2})(.+?)(:same)?\))")
12
 
 
142
  else [escape(m.from_user.first_name)],
143
  ),
144
  chatname=escape(m.chat.title)
145
+ chat_type = chattype(_,m)
146
+ if chat_type != "supergroup" or chat_type != "group"
147
  else escape(m.from_user.first_name),
148
  id=m.from_user.id,
149
  )