Spaces:
Sleeping
Sleeping
Captain Ezio
commited on
Commit
·
5ed2636
1
Parent(s):
9979a5a
Looks good
Browse files- Powers/__init__.py +2 -4
- Powers/database/approve_db.py +1 -2
- Powers/database/blacklist_db.py +1 -2
- Powers/database/disable_db.py +2 -4
- Powers/database/filters_db.py +1 -2
- Powers/database/greetings_db.py +1 -2
- Powers/database/notes_db.py +1 -2
- Powers/database/reporting_db.py +2 -4
- Powers/database/rules_db.py +1 -2
- Powers/database/users_db.py +1 -2
- Powers/plugins/admin.py +1 -2
- Powers/plugins/approve.py +2 -4
- Powers/plugins/blacklist.py +4 -8
- Powers/plugins/chat_blacklist.py +1 -2
- Powers/plugins/dev.py +1 -2
- Powers/plugins/disable.py +1 -2
- Powers/plugins/filters.py +3 -6
- Powers/plugins/fun.py +2 -4
- Powers/plugins/locks.py +5 -10
- Powers/plugins/notes.py +4 -8
- Powers/plugins/pin.py +5 -10
- Powers/plugins/purge.py +2 -2
- Powers/plugins/rules.py +3 -6
- Powers/plugins/start.py +2 -4
- Powers/plugins/warns.py +1 -2
- Powers/plugins/watchers.py +4 -8
- Powers/utils/caching.py +1 -2
- Powers/utils/extract_user.py +1 -1
- Powers/utils/extras.py +1 -2
- Powers/utils/start_utils.py +1 -1
- Powers/utils/string.py +5 -7
Powers/__init__.py
CHANGED
@@ -99,8 +99,7 @@ async def load_cmds(all_plugins):
|
|
99 |
for single in all_plugins:
|
100 |
# If plugin in NO_LOAD, skip the plugin
|
101 |
if single.lower() in [i.lower() for i in Config.NO_LOAD]:
|
102 |
-
LOGGER.warning(
|
103 |
-
f"Not loading '{single}' s it's added in NO_LOAD list")
|
104 |
continue
|
105 |
|
106 |
imported_module = imp_mod(f"Powers.plugins.{single}")
|
@@ -141,7 +140,6 @@ async def load_cmds(all_plugins):
|
|
141 |
LOGGER.warning(f"Not loading Plugins - {NO_LOAD}")
|
142 |
|
143 |
return (
|
144 |
-
", ".join((i.split(".")[1]).capitalize()
|
145 |
-
for i in list(HELP_COMMANDS.keys()))
|
146 |
+ "\n"
|
147 |
)
|
|
|
99 |
for single in all_plugins:
|
100 |
# If plugin in NO_LOAD, skip the plugin
|
101 |
if single.lower() in [i.lower() for i in Config.NO_LOAD]:
|
102 |
+
LOGGER.warning(f"Not loading '{single}' s it's added in NO_LOAD list")
|
|
|
103 |
continue
|
104 |
|
105 |
imported_module = imp_mod(f"Powers.plugins.{single}")
|
|
|
140 |
LOGGER.warning(f"Not loading Plugins - {NO_LOAD}")
|
141 |
|
142 |
return (
|
143 |
+
", ".join((i.split(".")[1]).capitalize() for i in list(HELP_COMMANDS.keys()))
|
|
|
144 |
+ "\n"
|
145 |
)
|
Powers/database/approve_db.py
CHANGED
@@ -66,8 +66,7 @@ class Approve(MongoDB):
|
|
66 |
if not chat_data:
|
67 |
new_data = {"_id": self.chat_id, "users": []}
|
68 |
self.insert_one(new_data)
|
69 |
-
LOGGER.info(
|
70 |
-
f"Initialized Approve Document for chat {self.chat_id}")
|
71 |
return new_data
|
72 |
return chat_data
|
73 |
|
|
|
66 |
if not chat_data:
|
67 |
new_data = {"_id": self.chat_id, "users": []}
|
68 |
self.insert_one(new_data)
|
69 |
+
LOGGER.info(f"Initialized Approve Document for chat {self.chat_id}")
|
|
|
70 |
return new_data
|
71 |
return chat_data
|
72 |
|
Powers/database/blacklist_db.py
CHANGED
@@ -110,8 +110,7 @@ class Blacklist(MongoDB):
|
|
110 |
"reason": "Automated blacklisted word: {{}}",
|
111 |
}
|
112 |
self.insert_one(new_data)
|
113 |
-
LOGGER.info(
|
114 |
-
f"Initialized Blacklist Document for chat {self.chat_id}")
|
115 |
return new_data
|
116 |
return chat_data
|
117 |
|
|
|
110 |
"reason": "Automated blacklisted word: {{}}",
|
111 |
}
|
112 |
self.insert_one(new_data)
|
113 |
+
LOGGER.info(f"Initialized Blacklist Document for chat {self.chat_id}")
|
|
|
114 |
return new_data
|
115 |
return chat_data
|
116 |
|
Powers/database/disable_db.py
CHANGED
@@ -146,11 +146,9 @@ class Disabling(MongoDB):
|
|
146 |
"commands": [],
|
147 |
"action": "none",
|
148 |
}
|
149 |
-
DISABLED_CMDS[self.chat_id] = {
|
150 |
-
"commands": [], "action": "none"}
|
151 |
self.insert_one(new_data)
|
152 |
-
LOGGER.info(
|
153 |
-
f"Initialized Disabling Document for chat {self.chat_id}")
|
154 |
return new_data
|
155 |
DISABLED_CMDS[self.chat_id] = chat_data
|
156 |
return chat_data
|
|
|
146 |
"commands": [],
|
147 |
"action": "none",
|
148 |
}
|
149 |
+
DISABLED_CMDS[self.chat_id] = {"commands": [], "action": "none"}
|
|
|
150 |
self.insert_one(new_data)
|
151 |
+
LOGGER.info(f"Initialized Disabling Document for chat {self.chat_id}")
|
|
|
152 |
return new_data
|
153 |
DISABLED_CMDS[self.chat_id] = chat_data
|
154 |
return chat_data
|
Powers/database/filters_db.py
CHANGED
@@ -71,8 +71,7 @@ class Filters(MongoDB):
|
|
71 |
curr = self.find_all()
|
72 |
if curr:
|
73 |
return len(
|
74 |
-
[z for z in (i["keyword"].split("|")
|
75 |
-
for i in curr) if len(z) >= 2],
|
76 |
)
|
77 |
return 0
|
78 |
|
|
|
71 |
curr = self.find_all()
|
72 |
if curr:
|
73 |
return len(
|
74 |
+
[z for z in (i["keyword"].split("|") for i in curr) if len(z) >= 2],
|
|
|
75 |
)
|
76 |
return 0
|
77 |
|
Powers/database/greetings_db.py
CHANGED
@@ -128,8 +128,7 @@ class Greetings(MongoDB):
|
|
128 |
"goodbye": True,
|
129 |
}
|
130 |
self.insert_one(new_data)
|
131 |
-
LOGGER.info(
|
132 |
-
f"Initialized Greetings Document for chat {self.chat_id}")
|
133 |
return new_data
|
134 |
return chat_data
|
135 |
|
|
|
128 |
"goodbye": True,
|
129 |
}
|
130 |
self.insert_one(new_data)
|
131 |
+
LOGGER.info(f"Initialized Greetings Document for chat {self.chat_id}")
|
|
|
132 |
return new_data
|
133 |
return chat_data
|
134 |
|
Powers/database/notes_db.py
CHANGED
@@ -57,8 +57,7 @@ class Notes(MongoDB):
|
|
57 |
def get_all_notes(self, chat_id: int):
|
58 |
with INSERTION_LOCK:
|
59 |
curr = self.find_all({"chat_id": chat_id})
|
60 |
-
note_list = sorted([(note["note_name"], note["hash"])
|
61 |
-
for note in curr])
|
62 |
return note_list
|
63 |
|
64 |
def rm_note(self, chat_id: int, note_name: str):
|
|
|
57 |
def get_all_notes(self, chat_id: int):
|
58 |
with INSERTION_LOCK:
|
59 |
curr = self.find_all({"chat_id": chat_id})
|
60 |
+
note_list = sorted([(note["note_name"], note["hash"]) for note in curr])
|
|
|
61 |
return note_list
|
62 |
|
63 |
def rm_note(self, chat_id: int, note_name: str):
|
Powers/database/reporting_db.py
CHANGED
@@ -42,11 +42,9 @@ class Reporting(MongoDB):
|
|
42 |
chat_data = self.find_one({"_id": self.chat_id})
|
43 |
if not chat_data:
|
44 |
chat_type = self.get_chat_type()
|
45 |
-
new_data = {"_id": self.chat_id,
|
46 |
-
"status": True, "chat_type": chat_type}
|
47 |
self.insert_one(new_data)
|
48 |
-
LOGGER.info(
|
49 |
-
f"Initialized Language Document for chat {self.chat_id}")
|
50 |
return new_data
|
51 |
return chat_data
|
52 |
|
|
|
42 |
chat_data = self.find_one({"_id": self.chat_id})
|
43 |
if not chat_data:
|
44 |
chat_type = self.get_chat_type()
|
45 |
+
new_data = {"_id": self.chat_id, "status": True, "chat_type": chat_type}
|
|
|
46 |
self.insert_one(new_data)
|
47 |
+
LOGGER.info(f"Initialized Language Document for chat {self.chat_id}")
|
|
|
48 |
return new_data
|
49 |
return chat_data
|
50 |
|
Powers/database/rules_db.py
CHANGED
@@ -68,8 +68,7 @@ class Rules(MongoDB):
|
|
68 |
if not chat_data:
|
69 |
new_data = {"_id": self.chat_id, "privrules": False, "rules": ""}
|
70 |
self.insert_one(new_data)
|
71 |
-
LOGGER.info(
|
72 |
-
f"Initialized Language Document for chat {self.chat_id}")
|
73 |
return new_data
|
74 |
return chat_data
|
75 |
|
|
|
68 |
if not chat_data:
|
69 |
new_data = {"_id": self.chat_id, "privrules": False, "rules": ""}
|
70 |
self.insert_one(new_data)
|
71 |
+
LOGGER.info(f"Initialized Language Document for chat {self.chat_id}")
|
|
|
72 |
return new_data
|
73 |
return chat_data
|
74 |
|
Powers/database/users_db.py
CHANGED
@@ -67,8 +67,7 @@ class Users(MongoDB):
|
|
67 |
def __ensure_in_db(self):
|
68 |
chat_data = self.find_one({"_id": self.user_id})
|
69 |
if not chat_data:
|
70 |
-
new_data = {"_id": self.user_id,
|
71 |
-
"username": "", "name": "unknown_till_now"}
|
72 |
self.insert_one(new_data)
|
73 |
LOGGER.info(f"Initialized User Document for {self.user_id}")
|
74 |
return new_data
|
|
|
67 |
def __ensure_in_db(self):
|
68 |
chat_data = self.find_one({"_id": self.user_id})
|
69 |
if not chat_data:
|
70 |
+
new_data = {"_id": self.user_id, "username": "", "name": "unknown_till_now"}
|
|
|
71 |
self.insert_one(new_data)
|
72 |
LOGGER.info(f"Initialized User Document for {self.user_id}")
|
73 |
return new_data
|
Powers/plugins/admin.py
CHANGED
@@ -40,8 +40,7 @@ async def adminlist_show(_, m: Message):
|
|
40 |
adminstr = f"Admins in <b>{m.chat.title}</b>:" + "\n\n"
|
41 |
|
42 |
bot_admins = [i for i in admin_list if (i[1].lower()).endswith("bot")]
|
43 |
-
user_admins = [i for i in admin_list if not (
|
44 |
-
i[1].lower()).endswith("bot")]
|
45 |
|
46 |
# format is like: (user_id, username/name,anonyamous or not)
|
47 |
mention_users = [
|
|
|
40 |
adminstr = f"Admins in <b>{m.chat.title}</b>:" + "\n\n"
|
41 |
|
42 |
bot_admins = [i for i in admin_list if (i[1].lower()).endswith("bot")]
|
43 |
+
user_admins = [i for i in admin_list if not (i[1].lower()).endswith("bot")]
|
|
|
44 |
|
45 |
# format is like: (user_id, username/name,anonyamous or not)
|
46 |
mention_users = [
|
Powers/plugins/approve.py
CHANGED
@@ -88,8 +88,7 @@ async def disapprove_user(c: Gojo, m: Message):
|
|
88 |
except UserNotParticipant:
|
89 |
if already_approved: # If user is approved and not in chat, unapprove them.
|
90 |
db.remove_approve(user_id)
|
91 |
-
LOGGER.info(
|
92 |
-
f"{user_id} disapproved in {m.chat.id} as UserNotParticipant")
|
93 |
await m.reply_text("This user is not in this chat, unapproved them.")
|
94 |
return
|
95 |
except RPCError as ef:
|
@@ -159,8 +158,7 @@ async def check_approval(c: Gojo, m: Message):
|
|
159 |
except Exception:
|
160 |
return
|
161 |
check_approve = db.check_approve(user_id)
|
162 |
-
LOGGER.info(
|
163 |
-
f"{m.from_user.id} checking approval of {user_id} in {m.chat.id}")
|
164 |
|
165 |
if not user_id:
|
166 |
await m.reply_text(
|
|
|
88 |
except UserNotParticipant:
|
89 |
if already_approved: # If user is approved and not in chat, unapprove them.
|
90 |
db.remove_approve(user_id)
|
91 |
+
LOGGER.info(f"{user_id} disapproved in {m.chat.id} as UserNotParticipant")
|
|
|
92 |
await m.reply_text("This user is not in this chat, unapproved them.")
|
93 |
return
|
94 |
except RPCError as ef:
|
|
|
158 |
except Exception:
|
159 |
return
|
160 |
check_approve = db.check_approve(user_id)
|
161 |
+
LOGGER.info(f"{m.from_user.id} checking approval of {user_id} in {m.chat.id}")
|
|
|
162 |
|
163 |
if not user_id:
|
164 |
await m.reply_text(
|
Powers/plugins/blacklist.py
CHANGED
@@ -55,8 +55,7 @@ async def add_blacklist(_, m: Message):
|
|
55 |
", ".join([f"<code>{i}</code>" for i in bl_words])
|
56 |
+ " already added in blacklist, skipped them!"
|
57 |
)
|
58 |
-
LOGGER.info(
|
59 |
-
f"{m.from_user.id} added new blacklists ({bl_words}) in {m.chat.id}")
|
60 |
trigger = ", ".join(f"<code>{i}</code>" for i in bl_words)
|
61 |
await m.reply_text(
|
62 |
text=f"Added <code>{trigger}</code> in blacklist words!"
|
@@ -111,12 +110,10 @@ async def rm_blacklist(_, m: Message):
|
|
111 |
|
112 |
if non_found_words:
|
113 |
rep_text = (
|
114 |
-
"Could not find " +
|
115 |
-
", ".join(f"<code>{i}</code>" for i in non_found_words)
|
116 |
) + " in blcklisted words, skipped them."
|
117 |
|
118 |
-
LOGGER.info(
|
119 |
-
f"{m.from_user.id} removed blacklists ({bl_words}) in {m.chat.id}")
|
120 |
bl_words = ", ".join(f"<code>{i}</code>" for i in bl_words)
|
121 |
await m.reply_text(
|
122 |
text=f"Removed <b>{bl_words}</b> from blacklist words!"
|
@@ -151,8 +148,7 @@ async def set_bl_action(_, m: Message):
|
|
151 |
await m.reply_text(text=f"Set action for blacklist for this to <b>{action}</b>")
|
152 |
elif len(m.text.split()) == 1:
|
153 |
action = db.get_action()
|
154 |
-
LOGGER.info(
|
155 |
-
f"{m.from_user.id} checking blacklist action in {m.chat.id}")
|
156 |
await m.reply_text(
|
157 |
text=f"""The current action for blacklists in this chat is <i><b>{action}</b></i>
|
158 |
All blacklist modes delete the message containing blacklist word."""
|
|
|
55 |
", ".join([f"<code>{i}</code>" for i in bl_words])
|
56 |
+ " already added in blacklist, skipped them!"
|
57 |
)
|
58 |
+
LOGGER.info(f"{m.from_user.id} added new blacklists ({bl_words}) in {m.chat.id}")
|
|
|
59 |
trigger = ", ".join(f"<code>{i}</code>" for i in bl_words)
|
60 |
await m.reply_text(
|
61 |
text=f"Added <code>{trigger}</code> in blacklist words!"
|
|
|
110 |
|
111 |
if non_found_words:
|
112 |
rep_text = (
|
113 |
+
"Could not find " + ", ".join(f"<code>{i}</code>" for i in non_found_words)
|
|
|
114 |
) + " in blcklisted words, skipped them."
|
115 |
|
116 |
+
LOGGER.info(f"{m.from_user.id} removed blacklists ({bl_words}) in {m.chat.id}")
|
|
|
117 |
bl_words = ", ".join(f"<code>{i}</code>" for i in bl_words)
|
118 |
await m.reply_text(
|
119 |
text=f"Removed <b>{bl_words}</b> from blacklist words!"
|
|
|
148 |
await m.reply_text(text=f"Set action for blacklist for this to <b>{action}</b>")
|
149 |
elif len(m.text.split()) == 1:
|
150 |
action = db.get_action()
|
151 |
+
LOGGER.info(f"{m.from_user.id} checking blacklist action in {m.chat.id}")
|
|
|
152 |
await m.reply_text(
|
153 |
text=f"""The current action for blacklists in this chat is <i><b>{action}</b></i>
|
154 |
All blacklist modes delete the message containing blacklist word."""
|
Powers/plugins/chat_blacklist.py
CHANGED
@@ -42,8 +42,7 @@ async def unblacklist_chat(c: Gojo, m: Message):
|
|
42 |
if len(m.text.split()) >= 2:
|
43 |
chat_ids = m.text.split()[1:]
|
44 |
replymsg = await m.reply_text(f"Removing {len(chat_ids)} chats from blacklist")
|
45 |
-
LOGGER.info(
|
46 |
-
f"{m.from_user.id} removed blacklisted {chat_ids} groups for bot")
|
47 |
bl_chats = db.list_all_chats()
|
48 |
for chat in chat_ids:
|
49 |
try:
|
|
|
42 |
if len(m.text.split()) >= 2:
|
43 |
chat_ids = m.text.split()[1:]
|
44 |
replymsg = await m.reply_text(f"Removing {len(chat_ids)} chats from blacklist")
|
45 |
+
LOGGER.info(f"{m.from_user.id} removed blacklisted {chat_ids} groups for bot")
|
|
|
46 |
bl_chats = db.list_all_chats()
|
47 |
for chat in chat_ids:
|
48 |
try:
|
Powers/plugins/dev.py
CHANGED
@@ -129,8 +129,7 @@ async def evaluate_code(c: Gojo, m: Message):
|
|
129 |
|
130 |
|
131 |
async def aexec(code, c, m):
|
132 |
-
exec("async def __aexec(c, m): " +
|
133 |
-
"".join(f"\n {l}" for l in code.split("\n")))
|
134 |
return await locals()["__aexec"](c, m)
|
135 |
|
136 |
|
|
|
129 |
|
130 |
|
131 |
async def aexec(code, c, m):
|
132 |
+
exec("async def __aexec(c, m): " + "".join(f"\n {l}" for l in code.split("\n")))
|
|
|
133 |
return await locals()["__aexec"](c, m)
|
134 |
|
135 |
|
Powers/plugins/disable.py
CHANGED
@@ -116,8 +116,7 @@ async def rm_alldisbl(_, m: Message):
|
|
116 |
"Confirm",
|
117 |
callback_data="enableallcmds",
|
118 |
),
|
119 |
-
InlineKeyboardButton(
|
120 |
-
"Cancel", callback_data="close_admin"),
|
121 |
],
|
122 |
],
|
123 |
),
|
|
|
116 |
"Confirm",
|
117 |
callback_data="enableallcmds",
|
118 |
),
|
119 |
+
InlineKeyboardButton("Cancel", callback_data="close_admin"),
|
|
|
120 |
],
|
121 |
],
|
122 |
),
|
Powers/plugins/filters.py
CHANGED
@@ -95,8 +95,7 @@ async def add_filter(_, m: Message):
|
|
95 |
)
|
96 |
|
97 |
add = db.save_filter(m.chat.id, keyword, teks, msgtype, file_id)
|
98 |
-
LOGGER.info(
|
99 |
-
f"{m.from_user.id} added new filter ({keyword}) in {m.chat.id}")
|
100 |
if add:
|
101 |
await m.reply_text(
|
102 |
f"Saved filter for '<code>{', '.join(keyword.split('|'))}</code>' in <b>{m.chat.title}</b>!",
|
@@ -120,8 +119,7 @@ async def stop_filter(_, m: Message):
|
|
120 |
for keyword in act_filters:
|
121 |
if keyword == m.text.split(None, 1)[1].lower():
|
122 |
db.rm_filter(m.chat.id, m.text.split(None, 1)[1].lower())
|
123 |
-
LOGGER.info(
|
124 |
-
f"{m.from_user.id} removed filter ({keyword}) in {m.chat.id}")
|
125 |
await m.reply_text(
|
126 |
f"Okay, I'll stop replying to that filter and it's aliases in <b>{m.chat.title}</b>.",
|
127 |
)
|
@@ -282,8 +280,7 @@ async def filters_watcher(c: Gojo, m: Message):
|
|
282 |
if match:
|
283 |
try:
|
284 |
msgtype = await send_filter_reply(c, m, trigger)
|
285 |
-
LOGGER.info(
|
286 |
-
f"Replied with {msgtype} to {trigger} in {m.chat.id}")
|
287 |
except Exception as ef:
|
288 |
await m.reply_text(f"Error: {ef}")
|
289 |
LOGGER.error(ef)
|
|
|
95 |
)
|
96 |
|
97 |
add = db.save_filter(m.chat.id, keyword, teks, msgtype, file_id)
|
98 |
+
LOGGER.info(f"{m.from_user.id} added new filter ({keyword}) in {m.chat.id}")
|
|
|
99 |
if add:
|
100 |
await m.reply_text(
|
101 |
f"Saved filter for '<code>{', '.join(keyword.split('|'))}</code>' in <b>{m.chat.title}</b>!",
|
|
|
119 |
for keyword in act_filters:
|
120 |
if keyword == m.text.split(None, 1)[1].lower():
|
121 |
db.rm_filter(m.chat.id, m.text.split(None, 1)[1].lower())
|
122 |
+
LOGGER.info(f"{m.from_user.id} removed filter ({keyword}) in {m.chat.id}")
|
|
|
123 |
await m.reply_text(
|
124 |
f"Okay, I'll stop replying to that filter and it's aliases in <b>{m.chat.title}</b>.",
|
125 |
)
|
|
|
280 |
if match:
|
281 |
try:
|
282 |
msgtype = await send_filter_reply(c, m, trigger)
|
283 |
+
LOGGER.info(f"Replied with {msgtype} to {trigger} in {m.chat.id}")
|
|
|
284 |
except Exception as ef:
|
285 |
await m.reply_text(f"Error: {ef}")
|
286 |
LOGGER.error(ef)
|
Powers/plugins/fun.py
CHANGED
@@ -71,8 +71,7 @@ async def fun_slap(c: Gojo, m: Message):
|
|
71 |
hit = choice(extras.HIT)
|
72 |
throw = choice(extras.THROW)
|
73 |
|
74 |
-
reply = temp.format(user1=user1, user2=user2,
|
75 |
-
item=item, hits=hit, throws=throw)
|
76 |
await reply_text(reply)
|
77 |
LOGGER.info(f"{m.from_user.id} slaped in {m.chat.id}")
|
78 |
return
|
@@ -111,8 +110,7 @@ async def insult(c: Gojo, m: Message):
|
|
111 |
m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
|
112 |
)
|
113 |
await reply_text(Insult_omp)
|
114 |
-
LOGGER.info(
|
115 |
-
f"{m.from_user.id} insulted {user_first_name} in {m.chat.id}")
|
116 |
|
117 |
|
118 |
@Gojo.on_message(command("yes"))
|
|
|
71 |
hit = choice(extras.HIT)
|
72 |
throw = choice(extras.THROW)
|
73 |
|
74 |
+
reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw)
|
|
|
75 |
await reply_text(reply)
|
76 |
LOGGER.info(f"{m.from_user.id} slaped in {m.chat.id}")
|
77 |
return
|
|
|
110 |
m.reply_to_message.reply_text if m.reply_to_message else m.reply_text
|
111 |
)
|
112 |
await reply_text(Insult_omp)
|
113 |
+
LOGGER.info(f"{m.from_user.id} insulted {user_first_name} in {m.chat.id}")
|
|
|
114 |
|
115 |
|
116 |
@Gojo.on_message(command("yes"))
|
Powers/plugins/locks.py
CHANGED
@@ -55,8 +55,7 @@ async def lock_perm(c: Gojo, m: Message):
|
|
55 |
if lock_type == "all":
|
56 |
try:
|
57 |
await c.set_chat_permissions(chat_id, ChatPermissions())
|
58 |
-
LOGGER.info(
|
59 |
-
f"{m.from_user.id} locked all permissions in {m.chat.id}")
|
60 |
except ChatNotModified:
|
61 |
pass
|
62 |
except ChatAdminRequired:
|
@@ -123,8 +122,7 @@ async def lock_perm(c: Gojo, m: Message):
|
|
123 |
ChatPermissions(
|
124 |
can_send_messages=msg,
|
125 |
can_send_media_messages=media,
|
126 |
-
can_send_other_messages=any(
|
127 |
-
[stickers, animations, games, inlinebots]),
|
128 |
can_add_web_page_previews=webprev,
|
129 |
can_send_polls=polls,
|
130 |
can_change_info=info,
|
@@ -132,8 +130,7 @@ async def lock_perm(c: Gojo, m: Message):
|
|
132 |
can_pin_messages=pin,
|
133 |
),
|
134 |
)
|
135 |
-
LOGGER.info(
|
136 |
-
f"{m.from_user.id} locked selected permissions in {m.chat.id}")
|
137 |
except ChatNotModified:
|
138 |
pass
|
139 |
except ChatAdminRequired:
|
@@ -215,8 +212,7 @@ async def unlock_perm(c: Gojo, m: Message):
|
|
215 |
can_pin_messages=True,
|
216 |
),
|
217 |
)
|
218 |
-
LOGGER.info(
|
219 |
-
f"{m.from_user.id} unlocked all permissions in {m.chat.id}")
|
220 |
except ChatNotModified:
|
221 |
pass
|
222 |
except ChatAdminRequired:
|
@@ -289,8 +285,7 @@ async def unlock_perm(c: Gojo, m: Message):
|
|
289 |
return
|
290 |
|
291 |
try:
|
292 |
-
LOGGER.info(
|
293 |
-
f"{m.from_user.id} unlocked selected permissions in {m.chat.id}")
|
294 |
await c.set_chat_permissions(
|
295 |
chat_id,
|
296 |
ChatPermissions(
|
|
|
55 |
if lock_type == "all":
|
56 |
try:
|
57 |
await c.set_chat_permissions(chat_id, ChatPermissions())
|
58 |
+
LOGGER.info(f"{m.from_user.id} locked all permissions in {m.chat.id}")
|
|
|
59 |
except ChatNotModified:
|
60 |
pass
|
61 |
except ChatAdminRequired:
|
|
|
122 |
ChatPermissions(
|
123 |
can_send_messages=msg,
|
124 |
can_send_media_messages=media,
|
125 |
+
can_send_other_messages=any([stickers, animations, games, inlinebots]),
|
|
|
126 |
can_add_web_page_previews=webprev,
|
127 |
can_send_polls=polls,
|
128 |
can_change_info=info,
|
|
|
130 |
can_pin_messages=pin,
|
131 |
),
|
132 |
)
|
133 |
+
LOGGER.info(f"{m.from_user.id} locked selected permissions in {m.chat.id}")
|
|
|
134 |
except ChatNotModified:
|
135 |
pass
|
136 |
except ChatAdminRequired:
|
|
|
212 |
can_pin_messages=True,
|
213 |
),
|
214 |
)
|
215 |
+
LOGGER.info(f"{m.from_user.id} unlocked all permissions in {m.chat.id}")
|
|
|
216 |
except ChatNotModified:
|
217 |
pass
|
218 |
except ChatAdminRequired:
|
|
|
285 |
return
|
286 |
|
287 |
try:
|
288 |
+
LOGGER.info(f"{m.from_user.id} unlocked selected permissions in {m.chat.id}")
|
|
|
289 |
await c.set_chat_permissions(
|
290 |
chat_id,
|
291 |
ChatPermissions(
|
Powers/plugins/notes.py
CHANGED
@@ -73,8 +73,7 @@ async def get_note_func(c: Gojo, m: Message, note_name, priv_notes_status):
|
|
73 |
|
74 |
if priv_notes_status:
|
75 |
|
76 |
-
note_hash = next(i[1] for i in db.get_all_notes(
|
77 |
-
m.chat.id) if i[0] == note_name)
|
78 |
await reply_text(
|
79 |
f"Click on the button to get the note <code>{note_name}</code>",
|
80 |
reply_markup=ikb(
|
@@ -298,13 +297,11 @@ async def priv_notes(_, m: Message):
|
|
298 |
option = (m.text.split())[1]
|
299 |
if option in ("on", "yes"):
|
300 |
db_settings.set_privatenotes(chat_id, True)
|
301 |
-
LOGGER.info(
|
302 |
-
f"{m.from_user.id} enabled privatenotes in {m.chat.id}")
|
303 |
msg = "Set private notes to On"
|
304 |
elif option in ("off", "no"):
|
305 |
db_settings.set_privatenotes(chat_id, False)
|
306 |
-
LOGGER.info(
|
307 |
-
f"{m.from_user.id} disabled privatenotes in {m.chat.id}")
|
308 |
msg = "Set private notes to Off"
|
309 |
else:
|
310 |
msg = "Enter correct option"
|
@@ -312,8 +309,7 @@ async def priv_notes(_, m: Message):
|
|
312 |
elif len(m.text.split()) == 1:
|
313 |
curr_pref = db_settings.get_privatenotes(m.chat.id)
|
314 |
msg = msg = f"Private Notes: {curr_pref}"
|
315 |
-
LOGGER.info(
|
316 |
-
f"{m.from_user.id} fetched privatenotes preference in {m.chat.id}")
|
317 |
await m.reply_text(msg)
|
318 |
else:
|
319 |
await m.replt_text("Check help on how to use this command!")
|
|
|
73 |
|
74 |
if priv_notes_status:
|
75 |
|
76 |
+
note_hash = next(i[1] for i in db.get_all_notes(m.chat.id) if i[0] == note_name)
|
|
|
77 |
await reply_text(
|
78 |
f"Click on the button to get the note <code>{note_name}</code>",
|
79 |
reply_markup=ikb(
|
|
|
297 |
option = (m.text.split())[1]
|
298 |
if option in ("on", "yes"):
|
299 |
db_settings.set_privatenotes(chat_id, True)
|
300 |
+
LOGGER.info(f"{m.from_user.id} enabled privatenotes in {m.chat.id}")
|
|
|
301 |
msg = "Set private notes to On"
|
302 |
elif option in ("off", "no"):
|
303 |
db_settings.set_privatenotes(chat_id, False)
|
304 |
+
LOGGER.info(f"{m.from_user.id} disabled privatenotes in {m.chat.id}")
|
|
|
305 |
msg = "Set private notes to Off"
|
306 |
else:
|
307 |
msg = "Enter correct option"
|
|
|
309 |
elif len(m.text.split()) == 1:
|
310 |
curr_pref = db_settings.get_privatenotes(m.chat.id)
|
311 |
msg = msg = f"Private Notes: {curr_pref}"
|
312 |
+
LOGGER.info(f"{m.from_user.id} fetched privatenotes preference in {m.chat.id}")
|
|
|
313 |
await m.reply_text(msg)
|
314 |
else:
|
315 |
await m.replt_text("Check help on how to use this command!")
|
Powers/plugins/pin.py
CHANGED
@@ -92,8 +92,7 @@ async def unpin_message(c: Gojo, m: Message):
|
|
92 |
async def unpinall_message(_, m: Message):
|
93 |
await m.reply_text(
|
94 |
"Do you really want to unpin all messages in this chat?",
|
95 |
-
reply_markup=ikb(
|
96 |
-
[[("Yes", "unpin all in this chat"), ("No", "close_admin")]]),
|
97 |
)
|
98 |
return
|
99 |
|
@@ -116,8 +115,7 @@ async def unpinall_calllback(c: Gojo, q: CallbackQuery):
|
|
116 |
return
|
117 |
try:
|
118 |
await c.unpin_all_chat_messages(q.message.chat.id)
|
119 |
-
LOGGER.info(
|
120 |
-
f"{q.from_user.id} unpinned all messages in {q.message.chat.id}")
|
121 |
await q.message.edit_text(text="Unpinned all messages in this chat.")
|
122 |
except ChatAdminRequired:
|
123 |
await q.message.edit_text(text="I'm not admin or I don't have rights.")
|
@@ -145,13 +143,11 @@ async def anti_channel_pin(_, m: Message):
|
|
145 |
if len(m.text.split()) == 2:
|
146 |
if m.command[1] in ("yes", "on", "true"):
|
147 |
pinsdb.antichannelpin_on()
|
148 |
-
LOGGER.info(
|
149 |
-
f"{m.from_user.id} enabled antichannelpin in {m.chat.id}")
|
150 |
msg = "Turned on AntiChannelPin, now all message pinned by channel will be unpinned automtically!"
|
151 |
elif m.command[1] in ("no", "off", "false"):
|
152 |
pinsdb.antichannelpin_off()
|
153 |
-
LOGGER.info(
|
154 |
-
f"{m.from_user.id} disabled antichannelpin in {m.chat.id}")
|
155 |
msg = "Turned off AntiChannelPin, now all message pinned by channel will stay pinned!"
|
156 |
else:
|
157 |
await m.reply_text(
|
@@ -203,8 +199,7 @@ async def clean_linked(_, m: Message):
|
|
203 |
msg = "Turned on CleanLinked! Now all the messages from linked channel will be deleted!"
|
204 |
elif m.command[1] in ("no", "off", "false"):
|
205 |
pinsdb.cleanlinked_off()
|
206 |
-
LOGGER.info(
|
207 |
-
f"{m.from_user.id} disabled CleanLinked in {m.chat.id}")
|
208 |
msg = "Turned off CleanLinked! Messages from linked channel will not be deleted!"
|
209 |
else:
|
210 |
await m.reply_text(
|
|
|
92 |
async def unpinall_message(_, m: Message):
|
93 |
await m.reply_text(
|
94 |
"Do you really want to unpin all messages in this chat?",
|
95 |
+
reply_markup=ikb([[("Yes", "unpin all in this chat"), ("No", "close_admin")]]),
|
|
|
96 |
)
|
97 |
return
|
98 |
|
|
|
115 |
return
|
116 |
try:
|
117 |
await c.unpin_all_chat_messages(q.message.chat.id)
|
118 |
+
LOGGER.info(f"{q.from_user.id} unpinned all messages in {q.message.chat.id}")
|
|
|
119 |
await q.message.edit_text(text="Unpinned all messages in this chat.")
|
120 |
except ChatAdminRequired:
|
121 |
await q.message.edit_text(text="I'm not admin or I don't have rights.")
|
|
|
143 |
if len(m.text.split()) == 2:
|
144 |
if m.command[1] in ("yes", "on", "true"):
|
145 |
pinsdb.antichannelpin_on()
|
146 |
+
LOGGER.info(f"{m.from_user.id} enabled antichannelpin in {m.chat.id}")
|
|
|
147 |
msg = "Turned on AntiChannelPin, now all message pinned by channel will be unpinned automtically!"
|
148 |
elif m.command[1] in ("no", "off", "false"):
|
149 |
pinsdb.antichannelpin_off()
|
150 |
+
LOGGER.info(f"{m.from_user.id} disabled antichannelpin in {m.chat.id}")
|
|
|
151 |
msg = "Turned off AntiChannelPin, now all message pinned by channel will stay pinned!"
|
152 |
else:
|
153 |
await m.reply_text(
|
|
|
199 |
msg = "Turned on CleanLinked! Now all the messages from linked channel will be deleted!"
|
200 |
elif m.command[1] in ("no", "off", "false"):
|
201 |
pinsdb.cleanlinked_off()
|
202 |
+
LOGGER.info(f"{m.from_user.id} disabled CleanLinked in {m.chat.id}")
|
|
|
203 |
msg = "Turned off CleanLinked! Messages from linked channel will not be deleted!"
|
204 |
else:
|
205 |
await m.reply_text(
|
Powers/plugins/purge.py
CHANGED
@@ -19,7 +19,7 @@ async def purge(c: Gojo, m: Message):
|
|
19 |
|
20 |
def divide_chunks(l: list, n: int = 100):
|
21 |
for i in range(0, len(l), n):
|
22 |
-
yield l[i: i + n]
|
23 |
|
24 |
# Dielete messages in chunks of 100 messages
|
25 |
m_list = list(divide_chunks(message_ids))
|
@@ -66,7 +66,7 @@ async def spurge(c: Gojo, m: Message):
|
|
66 |
|
67 |
def divide_chunks(l: list, n: int = 100):
|
68 |
for i in range(0, len(l), n):
|
69 |
-
yield l[i: i + n]
|
70 |
|
71 |
# Dielete messages in chunks of 100 messages
|
72 |
m_list = list(divide_chunks(message_ids))
|
|
|
19 |
|
20 |
def divide_chunks(l: list, n: int = 100):
|
21 |
for i in range(0, len(l), n):
|
22 |
+
yield l[i : i + n]
|
23 |
|
24 |
# Dielete messages in chunks of 100 messages
|
25 |
m_list = list(divide_chunks(message_ids))
|
|
|
66 |
|
67 |
def divide_chunks(l: list, n: int = 100):
|
68 |
for i in range(0, len(l), n):
|
69 |
+
yield l[i : i + n]
|
70 |
|
71 |
# Dielete messages in chunks of 100 messages
|
72 |
m_list = list(divide_chunks(message_ids))
|
Powers/plugins/rules.py
CHANGED
@@ -93,13 +93,11 @@ async def priv_rules(_, m: Message):
|
|
93 |
option = (m.text.split())[1]
|
94 |
if option in ("on", "yes"):
|
95 |
db.set_privrules(True)
|
96 |
-
LOGGER.info(
|
97 |
-
f"{m.from_user.id} enabled privaterules in {m.chat.id}")
|
98 |
msg = f"Private Rules have been turned <b>on</b> for chat <b>{m.chat.title}</b>"
|
99 |
elif option in ("off", "no"):
|
100 |
db.set_privrules(False)
|
101 |
-
LOGGER.info(
|
102 |
-
f"{m.from_user.id} disbaled privaterules in {m.chat.id}")
|
103 |
msg = f"Private Rules have been turned <b>off</b> for chat <b>{m.chat.title}</b>"
|
104 |
else:
|
105 |
msg = "Option not valid, choose from <code>on</code>, <code>yes</code>, <code>off</code>, <code>no</code>"
|
@@ -109,8 +107,7 @@ async def priv_rules(_, m: Message):
|
|
109 |
msg = (
|
110 |
f"Current Preference for Private rules in this chat is: <b>{curr_pref}</b>"
|
111 |
)
|
112 |
-
LOGGER.info(
|
113 |
-
f"{m.from_user.id} fetched privaterules preference in {m.chat.id}")
|
114 |
await m.reply_text(msg)
|
115 |
else:
|
116 |
await m.reply_text(text="Please check help on how to use this this command.")
|
|
|
93 |
option = (m.text.split())[1]
|
94 |
if option in ("on", "yes"):
|
95 |
db.set_privrules(True)
|
96 |
+
LOGGER.info(f"{m.from_user.id} enabled privaterules in {m.chat.id}")
|
|
|
97 |
msg = f"Private Rules have been turned <b>on</b> for chat <b>{m.chat.title}</b>"
|
98 |
elif option in ("off", "no"):
|
99 |
db.set_privrules(False)
|
100 |
+
LOGGER.info(f"{m.from_user.id} disbaled privaterules in {m.chat.id}")
|
|
|
101 |
msg = f"Private Rules have been turned <b>off</b> for chat <b>{m.chat.title}</b>"
|
102 |
else:
|
103 |
msg = "Option not valid, choose from <code>on</code>, <code>yes</code>, <code>off</code>, <code>no</code>"
|
|
|
107 |
msg = (
|
108 |
f"Current Preference for Private rules in this chat is: <b>{curr_pref}</b>"
|
109 |
)
|
110 |
+
LOGGER.info(f"{m.from_user.id} fetched privaterules preference in {m.chat.id}")
|
|
|
111 |
await m.reply_text(msg)
|
112 |
else:
|
113 |
await m.reply_text(text="Please check help on how to use this this command.")
|
Powers/plugins/start.py
CHANGED
@@ -69,8 +69,7 @@ async def start(c: Gojo, m: Message):
|
|
69 |
await get_private_note(c, m, help_option)
|
70 |
return
|
71 |
if help_option.startswith("rules"):
|
72 |
-
LOGGER.info(
|
73 |
-
f"{m.from_user.id} fetched privaterules in {m.chat.id}")
|
74 |
await get_private_rules(c, m, help_option)
|
75 |
return
|
76 |
|
@@ -182,8 +181,7 @@ async def help_menu(_, m: Message):
|
|
182 |
help_msg, help_kb = await get_help_msg(m, help_option)
|
183 |
|
184 |
if not help_msg:
|
185 |
-
LOGGER.error(
|
186 |
-
f"No help_msg found for help_option - {help_option}!!")
|
187 |
return
|
188 |
|
189 |
LOGGER.info(
|
|
|
69 |
await get_private_note(c, m, help_option)
|
70 |
return
|
71 |
if help_option.startswith("rules"):
|
72 |
+
LOGGER.info(f"{m.from_user.id} fetched privaterules in {m.chat.id}")
|
|
|
73 |
await get_private_rules(c, m, help_option)
|
74 |
return
|
75 |
|
|
|
181 |
help_msg, help_kb = await get_help_msg(m, help_option)
|
182 |
|
183 |
if not help_msg:
|
184 |
+
LOGGER.error(f"No help_msg found for help_option - {help_option}!!")
|
|
|
185 |
return
|
186 |
|
187 |
LOGGER.info(
|
Powers/plugins/warns.py
CHANGED
@@ -204,8 +204,7 @@ async def list_warns(c: Gojo, m: Message):
|
|
204 |
await m.reply_text("This user has no warns!")
|
205 |
return
|
206 |
msg = f"{(await mention_html(user_first_name,user_id))} has <b>{num_warns}/{warn_settings['warn_limit']}</b> warns!\n\n<b>Reasons:</b>\n"
|
207 |
-
msg += "\n".join(
|
208 |
-
[("- No reason" if i is None else f" - {i}") for i in warns])
|
209 |
await m.reply_text(msg)
|
210 |
return
|
211 |
|
|
|
204 |
await m.reply_text("This user has no warns!")
|
205 |
return
|
206 |
msg = f"{(await mention_html(user_first_name,user_id))} has <b>{num_warns}/{warn_settings['warn_limit']}</b> warns!\n\n<b>Reasons:</b>\n"
|
207 |
+
msg += "\n".join([("- No reason" if i is None else f" - {i}") for i in warns])
|
|
|
208 |
await m.reply_text(msg)
|
209 |
return
|
210 |
|
Powers/plugins/watchers.py
CHANGED
@@ -29,19 +29,16 @@ async def antichanpin_cleanlinked(c: Gojo, m: Message):
|
|
29 |
curr = pins_db.get_settings()
|
30 |
if curr["antichannelpin"]:
|
31 |
await c.unpin_chat_message(chat_id=m.chat.id, message_id=msg_id)
|
32 |
-
LOGGER.info(
|
33 |
-
f"AntiChannelPin: msgid-{m.message_id} unpinned in {m.chat.id}")
|
34 |
if curr["cleanlinked"]:
|
35 |
await c.delete_messages(m.chat.id, msg_id)
|
36 |
-
LOGGER.info(
|
37 |
-
f"CleanLinked: msgid-{m.message_id} cleaned in {m.chat.id}")
|
38 |
except ChatAdminRequired:
|
39 |
await m.reply_text(
|
40 |
"Disabled antichannelpin as I don't have enough admin rights!",
|
41 |
)
|
42 |
pins_db.antichannelpin_off()
|
43 |
-
LOGGER.warning(
|
44 |
-
f"Disabled antichannelpin in {m.chat.id} as i'm not an admin.")
|
45 |
except Exception as ef:
|
46 |
LOGGER.error(ef)
|
47 |
LOGGER.error(format_exc())
|
@@ -192,8 +189,7 @@ async def gban_watcher(c: Gojo, m: Message):
|
|
192 |
|
193 |
To get unbanned, appeal at @{SUPPORT_GROUP}"""
|
194 |
)
|
195 |
-
LOGGER.info(
|
196 |
-
f"Banned user {m.from_user.id} in {m.chat.id} due to antispam")
|
197 |
return
|
198 |
except (ChatAdminRequired, UserAdminInvalid):
|
199 |
# Bot not admin in group and hence cannot ban users!
|
|
|
29 |
curr = pins_db.get_settings()
|
30 |
if curr["antichannelpin"]:
|
31 |
await c.unpin_chat_message(chat_id=m.chat.id, message_id=msg_id)
|
32 |
+
LOGGER.info(f"AntiChannelPin: msgid-{m.message_id} unpinned in {m.chat.id}")
|
|
|
33 |
if curr["cleanlinked"]:
|
34 |
await c.delete_messages(m.chat.id, msg_id)
|
35 |
+
LOGGER.info(f"CleanLinked: msgid-{m.message_id} cleaned in {m.chat.id}")
|
|
|
36 |
except ChatAdminRequired:
|
37 |
await m.reply_text(
|
38 |
"Disabled antichannelpin as I don't have enough admin rights!",
|
39 |
)
|
40 |
pins_db.antichannelpin_off()
|
41 |
+
LOGGER.warning(f"Disabled antichannelpin in {m.chat.id} as i'm not an admin.")
|
|
|
42 |
except Exception as ef:
|
43 |
LOGGER.error(ef)
|
44 |
LOGGER.error(format_exc())
|
|
|
189 |
|
190 |
To get unbanned, appeal at @{SUPPORT_GROUP}"""
|
191 |
)
|
192 |
+
LOGGER.info(f"Banned user {m.from_user.id} in {m.chat.id} due to antispam")
|
|
|
193 |
return
|
194 |
except (ChatAdminRequired, UserAdminInvalid):
|
195 |
# Bot not admin in group and hence cannot ban users!
|
Powers/utils/caching.py
CHANGED
@@ -13,8 +13,7 @@ THREAD_LOCK = RLock()
|
|
13 |
# admins stay cached for 30 mins
|
14 |
ADMIN_CACHE = TTLCache(maxsize=512, ttl=(60 * 30), timer=perf_counter)
|
15 |
# Block from refreshing admin list for 10 mins
|
16 |
-
TEMP_ADMIN_CACHE_BLOCK = TTLCache(
|
17 |
-
maxsize=512, ttl=(60 * 10), timer=perf_counter)
|
18 |
|
19 |
|
20 |
async def admin_cache_reload(m: Message or CallbackQuery, status=None) -> List[int]:
|
|
|
13 |
# admins stay cached for 30 mins
|
14 |
ADMIN_CACHE = TTLCache(maxsize=512, ttl=(60 * 30), timer=perf_counter)
|
15 |
# Block from refreshing admin list for 10 mins
|
16 |
+
TEMP_ADMIN_CACHE_BLOCK = TTLCache(maxsize=512, ttl=(60 * 10), timer=perf_counter)
|
|
|
17 |
|
18 |
|
19 |
async def admin_cache_reload(m: Message or CallbackQuery, status=None) -> List[int]:
|
Powers/utils/extract_user.py
CHANGED
@@ -27,7 +27,7 @@ async def extract_user(c: Gojo, m: Message) -> Tuple[int, str, str]:
|
|
27 |
elif required_entity.type in ("mention", "phone_number"):
|
28 |
# new long user ids are identified as phone_number
|
29 |
user_found = m.text[
|
30 |
-
required_entity.offset: (
|
31 |
required_entity.offset + required_entity.length
|
32 |
)
|
33 |
]
|
|
|
27 |
elif required_entity.type in ("mention", "phone_number"):
|
28 |
# new long user ids are identified as phone_number
|
29 |
user_found = m.text[
|
30 |
+
required_entity.offset : (
|
31 |
required_entity.offset + required_entity.length
|
32 |
)
|
33 |
]
|
Powers/utils/extras.py
CHANGED
@@ -514,8 +514,7 @@ TOSS = (
|
|
514 |
)
|
515 |
|
516 |
|
517 |
-
DECIDE = ("Yes.", "No.", "Maybe.", "Who the hell cares?",
|
518 |
-
"No one give a damn about it")
|
519 |
|
520 |
INSULT_STRINGS = [
|
521 |
"`Owww ... Such a stupid idiot.`",
|
|
|
514 |
)
|
515 |
|
516 |
|
517 |
+
DECIDE = ("Yes.", "No.", "Maybe.", "Who the hell cares?", "No one give a damn about it")
|
|
|
518 |
|
519 |
INSULT_STRINGS = [
|
520 |
"`Owww ... Such a stupid idiot.`",
|
Powers/utils/start_utils.py
CHANGED
@@ -28,7 +28,7 @@ async def gen_cmds_kb(m: Message or CallbackQuery):
|
|
28 |
cmds = sorted(list(HELP_COMMANDS.keys()))
|
29 |
kb = [cmd.lower() for cmd in cmds]
|
30 |
|
31 |
-
return [kb[i: i + 3] for i in range(0, len(kb), 3)]
|
32 |
|
33 |
|
34 |
async def gen_start_kb(q: Message or CallbackQuery):
|
|
|
28 |
cmds = sorted(list(HELP_COMMANDS.keys()))
|
29 |
kb = [cmd.lower() for cmd in cmds]
|
30 |
|
31 |
+
return [kb[i : i + 3] for i in range(0, len(kb), 3)]
|
32 |
|
33 |
|
34 |
async def gen_start_kb(q: Message or CallbackQuery):
|
Powers/utils/string.py
CHANGED
@@ -7,8 +7,7 @@ from Powers.utils.parser import escape_markdown
|
|
7 |
from pyrogram.types import Message, InlineKeyboardButton
|
8 |
|
9 |
|
10 |
-
BTN_URL_REGEX = compile_re(
|
11 |
-
r"(\[([^\[]+?)\]\(buttonurl:(?:/{0,2})(.+?)(:same)?\))")
|
12 |
|
13 |
|
14 |
async def extract_time(m: Message, time_val: str):
|
@@ -53,9 +52,8 @@ async def parse_button(text: str):
|
|
53 |
# if even, not escaped -> create button
|
54 |
if n_escapes % 2 == 0:
|
55 |
# create a thruple with button label, url, and newline status
|
56 |
-
buttons.append(
|
57 |
-
|
58 |
-
note_data += markdown_note[prev: match.start(1)]
|
59 |
prev = match.end(1)
|
60 |
# if odd, escaped -> move along
|
61 |
else:
|
@@ -99,7 +97,7 @@ async def escape_invalid_curly_brackets(text: str, valids: List[str]) -> str:
|
|
99 |
success = True
|
100 |
break
|
101 |
if success:
|
102 |
-
new_text += text[idx: idx + len(v) + 2]
|
103 |
idx += len(v) + 2
|
104 |
continue
|
105 |
new_text += "{{"
|
@@ -173,7 +171,7 @@ async def split_quotes(text: str):
|
|
173 |
# 1 to avoid starting quote, and counter is exclusive so avoids ending
|
174 |
key = await remove_escapes(text[1:counter].strip())
|
175 |
# index will be in range, or `else` would have been executed and returned
|
176 |
-
rest = text[counter + 1:].strip()
|
177 |
if not key:
|
178 |
key = text[0] + text[0]
|
179 |
return list(filter(None, [key, rest]))
|
|
|
7 |
from pyrogram.types import Message, InlineKeyboardButton
|
8 |
|
9 |
|
10 |
+
BTN_URL_REGEX = compile_re(r"(\[([^\[]+?)\]\(buttonurl:(?:/{0,2})(.+?)(:same)?\))")
|
|
|
11 |
|
12 |
|
13 |
async def extract_time(m: Message, time_val: str):
|
|
|
52 |
# if even, not escaped -> create button
|
53 |
if n_escapes % 2 == 0:
|
54 |
# create a thruple with button label, url, and newline status
|
55 |
+
buttons.append((match.group(2), match.group(3), bool(match.group(4))))
|
56 |
+
note_data += markdown_note[prev : match.start(1)]
|
|
|
57 |
prev = match.end(1)
|
58 |
# if odd, escaped -> move along
|
59 |
else:
|
|
|
97 |
success = True
|
98 |
break
|
99 |
if success:
|
100 |
+
new_text += text[idx : idx + len(v) + 2]
|
101 |
idx += len(v) + 2
|
102 |
continue
|
103 |
new_text += "{{"
|
|
|
171 |
# 1 to avoid starting quote, and counter is exclusive so avoids ending
|
172 |
key = await remove_escapes(text[1:counter].strip())
|
173 |
# index will be in range, or `else` would have been executed and returned
|
174 |
+
rest = text[counter + 1 :].strip()
|
175 |
if not key:
|
176 |
key = text[0] + text[0]
|
177 |
return list(filter(None, [key, rest]))
|