Skip to content

Commit

Permalink
Sourcery AI | Code Formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Awesome-RJ authored Jul 9, 2022
2 parents 3ba7946 + 2b8b2a3 commit 4080342
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 150 deletions.
23 changes: 12 additions & 11 deletions Skynet_System/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,27 @@ async def make_collections() -> str:
if (
await collection.count_documents({"_id": 1}, limit=1) == 0
): # Blacklisted words list
dictw = {"_id": 1}
dictw["blacklisted"] = []
dictw = {"_id": 1, "blacklisted": []}
await collection.insert_one(dictw)

if (
await collection.count_documents({"_id": 2}, limit=1) == 0
): # Blacklisted words in name list
dictw = {"_id": 2, "Type": "Wlc Blacklist"}
dictw["blacklisted_wlc"] = []
dictw = {"_id": 2, "Type": "Wlc Blacklist", "blacklisted_wlc": []}
await collection.insert_one(dictw)
if await collection.count_documents({"_id": 3}, limit=1) == 0: # Gbanned users list
dictw = {"_id": 3, "Type": "Gban:List"}
dictw["victim"] = []
dictw["gbanners"] = []
dictw["reason"] = []
dictw["proof_id"] = []
dictw = {
"_id": 3,
"Type": "Gban:List",
"victim": [],
"gbanners": [],
"reason": [],
"proof_id": [],
}

await collection.insert_one(dictw)
if await collection.count_documents({"_id": 4}, limit=1) == 0: # Rank tree list
sample_dict = {"_id": 4, "data": {}, "standalone": {}}
sample_dict["data"] = {}
sample_dict = {"_id": 4, "standalone": {}, "data": {}}
for x in Skynet:
sample_dict["data"][str(x)] = {}
sample_dict["standalone"][str(x)] = {
Expand Down
8 changes: 3 additions & 5 deletions Skynet_System/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

for load in to_load:
try:
imported = importlib.import_module("Skynet_System.plugins." + load)
imported = importlib.import_module(f"Skynet_System.plugins.{load}")
if not hasattr(imported, "__plugin_name__"):
imported.__plugin_name__ = imported.__name__

if not imported.__plugin_name__.lower() in IMPORTED:
if imported.__plugin_name__.lower() not in IMPORTED:
IMPORTED[imported.__plugin_name__.lower()] = imported

if hasattr(imported, "help_plus") and imported.help_plus:
Expand Down Expand Up @@ -71,9 +71,7 @@ async def stats(event):
msg += f"\n{len(ENFORCERS)} Enforcers & {len(INSPECTORS)} Inspectors"
g = 0
async for d in event.client.iter_dialogs(limit=None):
if d.is_channel and not d.entity.broadcast:
g += 1
elif d.is_group:
if d.is_channel and not d.entity.broadcast or d.is_group:
g += 1
msg += f"\nModerating {g} Groups"
await event.reply(msg)
Expand Down
15 changes: 4 additions & 11 deletions Skynet_System/client_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ async def flags_decorator(event):
try:
if allow_unknown:
flags, unknown = parser.parse(split[1], known=True)
if unknown:
if any([x for x in unknown if '-' in x]):
parser.parse(split[1]) # Trigger the error because unknown args are not allowed to have - in them.
if unknown and any(x for x in unknown if '-' in x):
parser.parse(split[1]) # Trigger the error because unknown args are not allowed to have - in them.
else:
flags = parser.parse(split[1])
except ParseError as exce:
Expand Down Expand Up @@ -83,10 +82,7 @@ async def gban(
message=False,
) -> bool:
"""Gbans & Fbans user."""
if self.gban_logs:
logs = self.gban_logs
else:
logs = self.log
logs = self.gban_logs or self.log
if not auto:
await self.send_message(
logs,
Expand Down Expand Up @@ -128,10 +124,7 @@ async def gban(
)

async def ungban(self, target: int = None, reason: str = None) -> bool:
if self.gban_logs:
logs = self.gban_logs
else:
logs = self.log
logs = self.gban_logs or self.log
if not (await delete_gban(target)):
return False
await self.send_message(
Expand Down
18 changes: 6 additions & 12 deletions Skynet_System/plugins/Mongo_DB/message_blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ async def get_blacklist():


async def update_blacklist(word, add=False):
# cant find better names
upd = {}
owo = {}
bl = await db.find_one({"_id": 1})
current = bl["blacklisted"]
if add:
if word in current:
return False
if add and word in current or not add and word not in current:
return False
elif add:
current.append(word)
else:
if word in current:
current.remove(word)
else:
return False
upd["blacklisted"] = current
owo["$set"] = upd
current.remove(word)
upd = {"blacklisted": current}
owo = {"$set": upd}
await db.update_one(await db.find_one({"_id": 1}), owo)
return True
11 changes: 4 additions & 7 deletions Skynet_System/plugins/Mongo_DB/name_blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ async def update_wlc_blacklist(word, add=False):
bl = await db.find_one({"_id": 2})
current = bl["blacklisted_wlc"]
upd, owo = {}, {}
if add:
if word in current:
return False
if add and word in current or not add and word not in current:
return False
elif add:
current.append(word)
else:
if word in current:
current.remove(word)
else:
return False
current.remove(word)
upd["blacklisted_wlc"] = current
owo["$set"] = upd
await db.update_one(await db.find_one({"_id": 2}), owo)
Expand Down
18 changes: 8 additions & 10 deletions Skynet_System/plugins/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
async def extract(flag, event):
if flag:
return re.escape(flag.group(1))
else:
try:
text = event.text.split(" ", 1)[1]
return text
except BaseException:
return False
try:
return event.text.split(" ", 1)[1]
except BaseException:
return False


@System.on(system_cmd(pattern=r"addbl ", allow_slash=False))
Expand Down Expand Up @@ -116,7 +114,7 @@ async def auto_wlc_gban(event):
if words:
text = user.first_name
if user.last_name:
text = text + " " + user.last_name
text = f"{text} {user.last_name}"
for word in words:
pattern = r"( |^|[^\w])" + word + r"( |$|[^\w])"
if re.search(pattern, text, flags=re.IGNORECASE):
Expand All @@ -142,12 +140,12 @@ async def get(event):
words = await wlc_collection.get_wlc_bl()
else:
return
which = re.match(r".get (\d)x(\d+)", event.text)
if which:
if which := re.match(r".get (\d)x(\d+)", event.text):
try:
await event.reply(
f"Info from type {which.group(1)}\nPostion: {which.group(2)}\nMatches:{words[int(which.group(2))]}"
f"Info from type {which[1]}\nPostion: {which[2]}\nMatches:{words[int(which[2])]}"
)

except Exception:
return

Expand Down
19 changes: 7 additions & 12 deletions Skynet_System/plugins/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
DATA_LOCK = asyncio.Lock()

def can_ban(event):
status = False
if event.chat.admin_rights:
status = event.chat.admin_rights.ban_users
return status
return event.chat.admin_rights.ban_users if event.chat.admin_rights else False

async def make_proof(user: Union[str, int]):
if isinstance(user, str) and user.startswith('#'):
Expand Down Expand Up @@ -220,13 +217,11 @@ async def check_user(event):
return
if event.user_added:
if user.is_self:
if await db.add_chat(event.chat_id):
msg = "Thanks for adding me here!\n"\
"Here are your current settings:\n"\
"Alert Mode: Warn"
await event.respond(msg)
else: # Chat already exists in database
if not await db.add_chat(event.chat_id):
return
msg = "Thanks for adding me here!\n"\
"Here are your current settings:\n"\
"Alert Mode: Warn"
else:
u = await get_gban(user.id)
chat = await db.get_chat(event.chat_id)
Expand Down Expand Up @@ -254,7 +249,7 @@ async def check_user(event):
else:
msg += "I can't ban users here, Changed mode to `warn`"
await db.change_settings(event.chat_id, True, "warn")
await event.respond(msg)
await event.respond(msg)
elif user.id in INSPECTORS or user.id in ENFORCERS:
return
else:
Expand Down Expand Up @@ -284,6 +279,6 @@ async def check_user(event):
else:
msg += "I can't ban users here, Changed mode to `warn`"
await db.change_settings(event.chat_id, True, "warn")

await event.respond(msg)

2 changes: 1 addition & 1 deletion Skynet_System/plugins/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def run(event):
f.write(final)
await System.send_file(event.chat_id, "exec.txt")
return
await event.reply(final + "`")
await event.reply(f"{final}`")


@System.on(system_cmd(pattern=r"Skynet (ev|eva|eval|py)"))
Expand Down
45 changes: 22 additions & 23 deletions Skynet_System/plugins/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ async def addenf(event) -> None:
with open(json_file, "w") as file:
json.dump(data, file, indent=4)
await System.send_message(event.chat_id, "Added to enforcers, Restarting...")
if not event.from_id.user_id in Skynet:
if event.from_id.user_id not in Skynet:
await add_enforcers(event.from_id.user_id, u_id)
await System.disconnect()
os.execl(sys.executable, sys.executable, *sys.argv)
sys.exit()
if not event.from_id.user_id in Skynet:
if event.from_id.user_id not in Skynet:
await add_enforcers(event.from_id.user_id, u_id)
await System.send_message(
event.chat_id, f"Added [{u_id}](tg://user?id={u_id}) to Enforcers"
Expand All @@ -89,11 +89,11 @@ async def rmenf(event) -> None:
str(u_id)
ENF = os.environ.get("ENFORCERS")
if ENF.endswith(u_id):
config["ENFORCERS"] = ENF.strip(" " + str(u_id))
config["ENFORCERS"] = ENF.strip(f" {u_id}")
elif ENF.startswith(u_id):
config["ENFORCERS"] = ENF.strip(str(u_id) + " ")
config["ENFORCERS"] = ENF.strip(f"{u_id} ")
else:
config["ENFORCERS"] = ENF.strip(" " + str(u_id) + " ")
config["ENFORCERS"] = ENF.strip(f" {u_id} ")
else:
with open(json_file, "r") as file:
data = json.load(file)
Expand Down Expand Up @@ -129,16 +129,16 @@ async def join(event) -> None:
link = event.text.split(" ", 1)[1]
except BaseException:
return
private = re.match(
if private := re.match(
r"(https?://)?(www\.)?t(elegram)?\.(dog|me|org)/joinchat/(.*)", link
)
if private:
await System(ImportChatInviteRequest(private.group(5)))
):
await System(ImportChatInviteRequest(private[5]))
await System.send_message(event.chat_id, "Joined chat!")
await System.send_message(
Skynet_logs,
f"{(await event.get_sender()).first_name} made Skynet join {private.group(5)}",
f"{(await event.get_sender()).first_name} made Skynet join {private[5]}",
)

else:
await System(JoinChannelRequest(link))
await System.send_message(event.chat_id, "Joined chat!")
Expand Down Expand Up @@ -203,11 +203,11 @@ async def rmins(event) -> None:
if HEROKU:
ENF = os.environ.get("INSPECTORS")
if ENF.endswith(u_id):
config["INSPECTORS"] = ENF.strip(" " + str(u_id))
config["INSPECTORS"] = ENF.strip(f" {u_id}")
elif ENF.startswith(u_id):
config["INSPECTORS"] = ENF.strip(str(u_id) + " ")
config["INSPECTORS"] = ENF.strip(f"{u_id} ")
else:
config["INSPECTORS"] = ENF.strip(" " + str(u_id) + " ")
config["INSPECTORS"] = ENF.strip(f" {u_id} ")
else:
with open(json_file, "r") as file:
data = json.load(file)
Expand All @@ -229,7 +229,7 @@ async def rmins(event) -> None:
@System.on(system_cmd(pattern=r"info ", allow_inspectors=True))
async def info(event) -> None:
data = (await get_data())["standalone"]
if not event.text.split(" ", 1)[1] in data.keys():
if event.text.split(" ", 1)[1] not in data.keys():
return
u = event.text.split(" ", 1)[1]
msg = f"User: {u}\n"
Expand All @@ -256,20 +256,19 @@ async def resolve(event) -> None:
link = event.text.split(" ", 1)[1]
except BaseException:
return
match = re.match(
if match := re.match(
r"(https?://)?(www\.)?t(elegram)?\.(dog|me|org)/joinchat/(.*)", link
)
if match:
):
try:
data = resolve_invite_link(match.group(5))
data = resolve_invite_link(match[5])
except BaseException:
await System.send_message(
event.chat_id, "Couldn't fetch data from that link"
)
return
await System.send_message(
event.chat_id,
f"Info from hash {match.group(5)}:\n**Link Creator**: {data[0]}\n**Chat ID**: {data[1]}",
f"Info from hash {match[5]}:\n**Link Creator**: {data[0]}\n**Chat ID**: {data[1]}",
)


Expand All @@ -279,12 +278,12 @@ async def leave(event) -> None:
link = event.text.split(" ", 1)[1]
except BaseException:
return
c_id = re.match(r"-(\d+)", link)
if c_id:
await System(LeaveChannelRequest(int(c_id.group(0))))
if c_id := re.match(r"-(\d+)", link):
await System(LeaveChannelRequest(int(c_id[0])))
await System.send_message(
event.chat_id, f"Skynet has left chat with id[-{c_id.group(1)}]"
event.chat_id, f"Skynet has left chat with id[-{c_id[1]}]"
)

else:
await System(LeaveChannelRequest(link))
await System.send_message(event.chat_id, f"Skynet has left chat[{link}]")
Expand Down
Loading

0 comments on commit 4080342

Please sign in to comment.