Skip to content

Commit

Permalink
almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgojoof6eyes committed Oct 21, 2024
1 parent 67f2e3f commit 56ff298
Show file tree
Hide file tree
Showing 58 changed files with 443 additions and 698 deletions.
20 changes: 4 additions & 16 deletions Powers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,11 @@
SUPPORT_GROUP = Config.SUPPORT_GROUP
SUPPORT_CHANNEL = Config.SUPPORT_CHANNEL

# Users Config
# Users Config
OWNER_ID = Config.OWNER_ID
DEV = Config.DEV_USERS
DEVS_USER = set(DEV)
SUDO_USERS = Config.SUDO_USERS
WHITELIST_USERS = Config.WHITELIST_USERS


defult_dev = [1344569458, 1432756163, 5294360309] + [int(OWNER_ID)]

Defult_dev = set(defult_dev)

DEVS = DEVS_USER | Defult_dev
DEV_USERS = list(DEVS)

CHROME_BIN = Config.CHROME_BIN
CHROME_DRIVER = Config.CHROME_DRIVER
DEV_USERS = set(Config.DEV_USERS)
SUDO_USERS = set(Config.SUDO_USERS)
WHITELIST_USERS = set(Config.WHITELIST_USERS)

# Plugins, DB and Workers
DB_URI = Config.DB_URI
Expand Down
1 change: 1 addition & 0 deletions Powers/bot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async def start(self):
# Get cmds and keys
cmd_list = await load_cmds(await all_plugins())
await load_support_users()
await cache_support()
LOGGER.info(f"Plugins Loaded: {cmd_list}")
scheduler.add_job(clean_my_db, 'cron', [
self], hour=3, minute=0, second=0)
Expand Down
3 changes: 2 additions & 1 deletion Powers/database/antispam_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def add_gban(self, user_id: int, reason: str, by_user: int):
return self.update_gban_reason(user_id, reason)

# If not already gbanned, then add to gban
ANTISPAM_BANNED.add(user_id)
time_rn = datetime.now(TZ)
return self.insert_one(
{
Expand All @@ -43,8 +44,8 @@ def remove_gban(self, user_id: int):
with INSERTION_LOCK:
# Check if user is already gbanned or not
if self.find_one({"_id": user_id}):
ANTISPAM_BANNED.remove(user_id)
return self.delete_one({"_id": user_id})

return "User not gbanned!"

def get_gban(self, user_id: int):
Expand Down
2 changes: 0 additions & 2 deletions Powers/database/approve_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ def __ensure_in_db(self):
if not chat_data:
new_data = {"_id": self.chat_id, "users": []}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Approve Document for chat {self.chat_id}")
return new_data
return chat_data
# Migrate if chat id changes!
Expand Down
2 changes: 0 additions & 2 deletions Powers/database/blacklist_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ def __ensure_in_db(self):
"reason": "Automated blacklisted word: {{}}",
}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Blacklist Document for chat {self.chat_id}")
return new_data
return chat_data

Expand Down
1 change: 0 additions & 1 deletion Powers/database/chats_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def __ensure_in_db(self):
if not chat_data:
new_data = {"_id": self.chat_id, "chat_name": "", "users": []}
self.insert_one(new_data)
LOGGER.info(f"Initialized Chats Document for chat {self.chat_id}")
return new_data
return chat_data

Expand Down
2 changes: 0 additions & 2 deletions Powers/database/disable_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ def __ensure_in_db(self):
DISABLED_CMDS[self.chat_id] = {
"commands": [], "action": "none"}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Disabling Document for chat {self.chat_id}")
return new_data
DISABLED_CMDS[self.chat_id] = chat_data
return chat_data
Expand Down
10 changes: 9 additions & 1 deletion Powers/database/filters_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ def save_filter(
# Database update
curr = self.find_one({"chat_id": chat_id, "keyword": keyword})
if curr:
return False
self.update(
{"chat_id": chat_id, "keyword": keyword},
{
"filter_reply": filter_reply,
"msgtype": msgtype,
"fileid": fileid
}
)
return
return self.insert_one(
{
"chat_id": chat_id,
Expand Down
2 changes: 0 additions & 2 deletions Powers/database/greetings_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def __ensure_in_db(self):
"goodbye_mtype": False
}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Greetings Document for chat {self.chat_id}")
return new_data
return chat_data

Expand Down
52 changes: 32 additions & 20 deletions Powers/database/locks_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,47 @@ def remove_lock_channel(self, chat: int, locktype: str):
else:
return False

def get_lock_channel(self, locktype: str = "all", chat: int = 0):
def get_lock_channel(self, chat: int, locktype: str = "all"):
"""
locktypes: anti_c_send, anti_fwd, anti_fwd_u, anti_fwd_c, anti_links, bot
"""
if locktype not in ["anti_c_send", "anti_fwd", "anti_fwd_u", "anti_fwd_c", "anti_links", "bot", "all"]:
return False
else:
if locktype == "all":
find = {}
if locktype != "all":
curr = self.find_one(
{"chat_id": chat, "locktype": locktype})
return bool(curr)
else:
find = {"locktype": locktype}
if chat:
if find:
curr = self.find_one(
{"chat_id": chat, "locktype": locktype})
return bool(curr)
else:
to_return = []
for i in lock_t:
curr = self.find_one({"chat_id": chat, "locktype": i})
to_return.append(bool(curr))
return all(to_return)
else:
curr = self.find_all(find)
to_return = {
"anti_channel": False,
"anti_fwd": {
"user": False,
"chat": False
},
"anti_links": False,
"bot": False
}
curr = self.find_all({"chat_id": chat})
if not curr:
list_ = []
return None
else:
list_ = [i["chat_id"] for i in curr]
return list_
for i in list(curr):
if i["locktype"] == "anti_c_send":
to_return["anti_channel"] = True
elif i["locktype"] == "anti_fwd":
to_return["anti_fwd"]["user"] = to_return["anti_fwd"]["chat"] = True
elif i["locktype"] == "anti_fwd_u":
to_return["anti_fwd"]["user"] = True
elif i["locktype"] == "anti_fwd_c":
to_return["anti_fwd"]["chat"] = True
elif i["anti_links"] == "anti_links":
to_return["anti_links"] = True
elif i["locktype"] == "bot":
to_return["bot"] = True
else:
continue
return to_return

def merge_u_and_c(self, chat: int, locktype: str):
if locktype == "anti_fwd_u":
Expand Down
1 change: 0 additions & 1 deletion Powers/database/pins_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def __ensure_in_db(self):
"cleanlinked": False,
}
self.insert_one(new_data)
LOGGER.info(f"Initialized Pins Document for chat {self.chat_id}")
return new_data
return chat_data

Expand Down
2 changes: 0 additions & 2 deletions Powers/database/reporting_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def __ensure_in_db(self):
new_data = {"_id": self.chat_id,
"status": True, "chat_type": chat_type}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Language Document for chat {self.chat_id}")
return new_data
return chat_data

Expand Down
2 changes: 0 additions & 2 deletions Powers/database/rules_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def __ensure_in_db(self):
if not chat_data:
new_data = {"_id": self.chat_id, "privrules": False, "rules": ""}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Language Document for chat {self.chat_id}")
return new_data
return chat_data

Expand Down
1 change: 0 additions & 1 deletion Powers/database/users_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def __ensure_in_db(self):
new_data = {"_id": self.user_id,
"username": "", "name": "unknown_till_now"}
self.insert_one(new_data)
LOGGER.info(f"Initialized User Document for {self.user_id}")
return new_data
return chat_data

Expand Down
4 changes: 0 additions & 4 deletions Powers/database/warns_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ def __ensure_in_db(self, user_id: int):
"num_warns": 0,
}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Warn Document for {user_id} in {self.chat_id}")
return new_data
return chat_data

Expand All @@ -129,8 +127,6 @@ def __ensure_in_db(self):
new_data = {"_id": self.chat_id,
"warn_mode": "none", "warn_limit": 3}
self.insert_one(new_data)
LOGGER.info(
f"Initialized Warn Settings Document for {self.chat_id}")
return new_data
return chat_data

Expand Down
29 changes: 11 additions & 18 deletions Powers/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@
RPCError, UserAdminInvalid)
from pyrogram.types import ChatPrivileges, Message

from Powers import LOGGER, OWNER_ID
from Powers import DEV_USERS, LOGGER, OWNER_ID, SUDO_USERS, WHITELIST_USERS
from Powers.bot_class import Gojo
from Powers.database.approve_db import Approve
from Powers.database.reporting_db import Reporting
from Powers.supports import get_support_staff
from Powers.utils.caching import (ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK,
admin_cache_reload)
from Powers.utils.custom_filters import (admin_filter, command, owner_filter,
promote_filter)
from Powers.utils.custom_filters import admin_filter, command, promote_filter
from Powers.utils.extract_user import extract_user
from Powers.utils.parser import mention_html
from Powers.vars import Config


@Gojo.on_message(command("adminlist"))
Expand Down Expand Up @@ -67,7 +64,7 @@ async def adminlist_show(_, m: Message):
adminstr += "\n\n<b>Bots:</b>\n"
adminstr += "\n".join(f"- {i}" for i in mention_bots)
await m.reply_text(adminstr + "\n\n" + note)
LOGGER.info(f"Adminlist cmd use in {m.chat.id} by {m.from_user.id}")

except Exception as ef:
if str(ef) == str(m.chat.id):
await m.reply_text(text="Use /admincache to reload admins!")
Expand Down Expand Up @@ -95,7 +92,11 @@ async def zombie_clean(c: Gojo, m: Message):
except UserAdminInvalid:
failed += 1
except FloodWait as e:
await sleep(e.x)
await sleep(e.value)
try:
await c.ban_chat_member(m.chat.id, member.user.id)
except:
pass
if zombie == 0:
return await wait.edit_text("Group is clean!")
await wait.delete()
Expand All @@ -110,7 +111,7 @@ async def reload_admins(_, m: Message):
return await m.reply_text(
"This command is made to be used in groups only!",
)
SUPPORT_STAFF = get_support_staff()
SUPPORT_STAFF = DEV_USERS.union(SUDO_USERS).union(WHITELIST_USERS)
if (
(m.chat.id in set(TEMP_ADMIN_CACHE_BLOCK.keys()))
and (m.from_user.id not in SUPPORT_STAFF)
Expand All @@ -122,7 +123,6 @@ async def reload_admins(_, m: Message):
await admin_cache_reload(m, "admincache")
TEMP_ADMIN_CACHE_BLOCK[m.chat.id] = "manualblock"
await m.reply_text(text="Reloaded all admins in this chat!")
LOGGER.info(f"Admincache cmd use in {m.chat.id} by {m.from_user.id}")
except RPCError as ef:
await m.reply_text(
text=f"Some error occured, report it using `/bug` \n <b>Error:</b> <code>{ef}</code>"
Expand Down Expand Up @@ -206,9 +206,6 @@ async def fullpromote_usr(c: Gojo, m: Message):
except Exception as e:
LOGGER.error(e)
LOGGER.error(format_exc())
LOGGER.info(
f"{m.from_user.id} fullpromoted {user_id} in {m.chat.id} with title '{title}'",
)
await m.reply_text(
(
"{promoter} promoted {promoted} in chat <b>{chat_title}</b> with full rights!"
Expand Down Expand Up @@ -311,9 +308,7 @@ async def promote_usr(c: Gojo, m: Message):
except Exception as e:
LOGGER.error(e)
LOGGER.error(format_exc())
LOGGER.info(
f"{m.from_user.id} promoted {user_id} in {m.chat.id} with title '{title}'",
)

await m.reply_text(
("{promoter} promoted {promoted} in chat <b>{chat_title}</b>!").format(
promoter=(await mention_html(m.from_user.first_name, m.from_user.id)),
Expand Down Expand Up @@ -382,7 +377,6 @@ async def demote_usr(c: Gojo, m: Message):
user_id=user_id,
privileges=ChatPrivileges(can_manage_chat=False),
)
LOGGER.info(f"{m.from_user.id} demoted {user_id} in {m.chat.id}")
# ----- Remove admin from cache -----
try:
admin_list = ADMIN_CACHE[m.chat.id]
Expand Down Expand Up @@ -426,7 +420,7 @@ async def demote_usr(c: Gojo, m: Message):
async def get_invitelink(c: Gojo, m: Message):
# Bypass the bot devs, sudos and owner

DEV_LEVEL = get_support_staff("dev_level")
DEV_LEVEL = DEV_USERS
if m.from_user.id not in DEV_LEVEL:
user = await m.chat.get_member(m.from_user.id)
if not user.privileges.can_invite_users and user.status != CMS.OWNER:
Expand All @@ -438,7 +432,6 @@ async def get_invitelink(c: Gojo, m: Message):
text=f"Invite Link for Chat <b>{m.chat.id}</b>: {link}",
disable_web_page_preview=True,
)
LOGGER.info(f"{m.from_user.id} exported invite link in {m.chat.id}")
except ChatAdminRequired:
await m.reply_text(text="I'm not admin or I don't have rights.")
except ChatAdminInviteRequired:
Expand Down
Loading

0 comments on commit 56ff298

Please sign in to comment.