Spaces:
Sleeping
Sleeping
File size: 6,507 Bytes
ca4eb6d |
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
from html import escape
from pyrogram import filters
from pyrogram.types import CallbackQuery, Message
from Powers import LOGGER
from Powers.bot_class import Gojo
from Powers.database.blacklist_db import Blacklist
from Powers.tr_engine import tlang
from Powers.utils.custom_filters import command, owner_filter, restrict_filter
from Powers.utils.kbhelpers import ikb
@Gojo.on_message(command("blacklist") & filters.group)
async def view_blacklist(_, m: Message):
db = Blacklist(m.chat.id)
LOGGER.info(f"{m.from_user.id} checking blacklists in {m.chat.id}")
chat_title = m.chat.title
blacklists_chat = (tlang(m, "blacklist.curr_blacklist_initial")).format(
chat_title=chat_title,
)
all_blacklisted = db.get_blacklists()
if not all_blacklisted:
await m.reply_text(
(tlang(m, "blacklist.no_blacklist")).format(
chat_title=chat_title,
),
)
return
blacklists_chat += "\n".join(
f" • <code>{escape(i)}</code>" for i in all_blacklisted
)
await m.reply_text(blacklists_chat)
return
@Gojo.on_message(command("addblacklist") & restrict_filter)
async def add_blacklist(_, m: Message):
db = Blacklist(m.chat.id)
if len(m.text.split()) < 2:
await m.reply_text(tlang(m, "general.check_help"))
return
bl_words = ((m.text.split(None, 1)[1]).lower()).split()
all_blacklisted = db.get_blacklists()
already_added_words, rep_text = [], ""
for bl_word in bl_words:
if bl_word in all_blacklisted:
already_added_words.append(bl_word)
continue
db.add_blacklist(bl_word)
if already_added_words:
rep_text = (
", ".join([f"<code>{i}</code>" for i in bl_words])
+ " already added in blacklist, skipped them!"
)
LOGGER.info(f"{m.from_user.id} added new blacklists ({bl_words}) in {m.chat.id}")
await m.reply_text(
(tlang(m, "blacklist.added_blacklist")).format(
trigger=", ".join(f"<code>{i}</code>" for i in bl_words),
)
+ (f"\n{rep_text}" if rep_text else ""),
)
await m.stop_propagation()
@Gojo.on_message(
command(["blwarning", "blreason", "blacklistreason"]) & restrict_filter,
)
async def blacklistreason(_, m: Message):
db = Blacklist(m.chat.id)
if len(m.text.split()) == 1:
curr = db.get_reason()
await m.reply_text(
f"The current reason for blacklists warn is:\n<code>{curr}</code>",
)
else:
reason = m.text.split(None, 1)[1]
db.set_reason(reason)
await m.reply_text(
f"Updated reason for blacklists warn is:\n<code>{reason}</code>",
)
return
@Gojo.on_message(
command(["rmblacklist", "unblacklist"]) & restrict_filter,
)
async def rm_blacklist(_, m: Message):
db = Blacklist(m.chat.id)
if len(m.text.split()) < 2:
await m.reply_text(tlang(m, "general.check_help"))
return
chat_bl = db.get_blacklists()
non_found_words, rep_text = [], ""
bl_words = ((m.text.split(None, 1)[1]).lower()).split()
for bl_word in bl_words:
if bl_word not in chat_bl:
non_found_words.append(bl_word)
continue
db.remove_blacklist(bl_word)
if non_found_words == bl_words:
return await m.reply_text("Blacklists not found!")
if non_found_words:
rep_text = (
"Could not find " + ", ".join(f"<code>{i}</code>" for i in non_found_words)
) + " in blcklisted words, skipped them."
LOGGER.info(f"{m.from_user.id} removed blacklists ({bl_words}) in {m.chat.id}")
await m.reply_text(
(tlang(m, "blacklist.rm_blacklist")).format(
bl_words=", ".join(f"<code>{i}</code>" for i in bl_words),
)
+ (f"\n{rep_text}" if rep_text else ""),
)
await m.stop_propagation()
@Gojo.on_message(
command(["blaction", "blacklistaction", "blacklistmode"]) & restrict_filter,
)
async def set_bl_action(_, m: Message):
db = Blacklist(m.chat.id)
if len(m.text.split()) == 2:
action = m.text.split(None, 1)[1]
valid_actions = ("ban", "kick", "mute", "warn", "none")
if action not in valid_actions:
await m.reply_text(
(
"Choose a valid blacklist action from "
+ ", ".join(f"<code>{i}</code>" for i in valid_actions)
),
)
return
db.set_action(action)
LOGGER.info(
f"{m.from_user.id} set blacklist action to '{action}' in {m.chat.id}",
)
await m.reply_text(
(tlang(m, "blacklist.action_set")).format(action=action),
)
elif len(m.text.split()) == 1:
action = db.get_action()
LOGGER.info(f"{m.from_user.id} checking blacklist action in {m.chat.id}")
await m.reply_text(
(tlang(m, "blacklist.action_get")).format(action=action),
)
else:
await m.reply_text(tlang(m, "general.check_help"))
return
@Gojo.on_message(
command("rmallblacklist") & owner_filter,
)
async def rm_allblacklist(_, m: Message):
db = Blacklist(m.chat.id)
all_bls = db.get_blacklists()
if not all_bls:
await m.reply_text("No notes are blacklists in this chat")
return
await m.reply_text(
"Are you sure you want to clear all blacklists?",
reply_markup=ikb(
[[("⚠️ Confirm", "rm_allblacklist"), ("❌ Cancel", "close_admin")]],
),
)
return
@Gojo.on_callback_query(filters.regex("^rm_allblacklist$"))
async def rm_allbl_callback(_, q: CallbackQuery):
user_id = q.from_user.id
db = Blacklist(q.message.chat.id)
user_status = (await q.message.chat.get_member(user_id)).status
if user_status not in {"creator", "administrator"}:
await q.answer(
"You're not even an admin, don't try this explosive shit!",
show_alert=True,
)
return
if user_status != "creator":
await q.answer(
"You're just an admin, not owner\nStay in your limits!",
show_alert=True,
)
return
db.rm_all_blacklist()
await q.message.delete()
LOGGER.info(f"{user_id} removed all blacklists in {q.message.chat.id}")
await q.answer("Cleared all Blacklists!", show_alert=True)
return
__PLUGIN__ = "blacklist"
__alt_name__ = ["blacklists", "blaction"]
|