Skip to content

Commit

Permalink
Automated code formatting
Browse files Browse the repository at this point in the history
Signed-off-by: jankarikiduniya <jankarikiduniya@users.noreply.github.com>
  • Loading branch information
TheTeamAlexa authored and jankarikiduniya committed Oct 5, 2022
1 parent 7ddc2f7 commit 40f62d3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 114 deletions.
41 changes: 18 additions & 23 deletions AlexaMusic/plugins/modules/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
from strings import get_command
from AlexaMusic import app, userbot
from AlexaMusic.misc import SUDOERS
from AlexaMusic.utils.database import (get_active_chats,
get_authuser_names, get_client,
get_particular_top,
get_served_chats,
get_served_users, get_user_top,
is_cleanmode_on, set_queries,
update_particular_top,
update_user_top)
from AlexaMusic.utils.database import (
get_active_chats,
get_authuser_names,
get_client,
get_particular_top,
get_served_chats,
get_served_users,
get_user_top,
is_cleanmode_on,
set_queries,
update_particular_top,
update_user_top,
)
from AlexaMusic.utils.decorators.language import language
from AlexaMusic.utils.formatters import alpha_to_int

Expand Down Expand Up @@ -211,15 +216,11 @@ async def auto_clean():
spot = spot["spot"]
next_spot = spot + 1
new_spot = {"spot": next_spot, "title": title}
await update_particular_top(
chat_id, vidid, new_spot
)
await update_particular_top(chat_id, vidid, new_spot)
else:
next_spot = 1
new_spot = {"spot": next_spot, "title": title}
await update_particular_top(
chat_id, vidid, new_spot
)
await update_particular_top(chat_id, vidid, new_spot)
for user_id in userstats:
for dic in userstats[user_id]:
vidid = dic["vidid"]
Expand All @@ -230,15 +231,11 @@ async def auto_clean():
spot = spot["spot"]
next_spot = spot + 1
new_spot = {"spot": next_spot, "title": title}
await update_user_top(
user_id, vidid, new_spot
)
await update_user_top(user_id, vidid, new_spot)
else:
next_spot = 1
new_spot = {"spot": next_spot, "title": title}
await update_user_top(
user_id, vidid, new_spot
)
await update_user_top(user_id, vidid, new_spot)
except:
continue
try:
Expand All @@ -248,9 +245,7 @@ async def auto_clean():
for x in clean[chat_id]:
if datetime.now() > x["timer_after"]:
try:
await app.delete_messages(
chat_id, x["msg_id"]
)
await app.delete_messages(chat_id, x["msg_id"])
except FloodWait as e:
await asyncio.sleep(e.x)
except:
Expand Down
34 changes: 13 additions & 21 deletions AlexaMusic/plugins/modules/punishment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
from AlexaMusic import app
from AlexaMusic.misc import SUDOERS
from AlexaMusic.utils import get_readable_time
from AlexaMusic.utils.database import (add_banned_user,
get_banned_count,
get_banned_users,
get_served_chats,
is_banned_user,
remove_banned_user)
from AlexaMusic.utils.database import (
add_banned_user,
get_banned_count,
get_banned_users,
get_served_chats,
is_banned_user,
remove_banned_user,
)
from AlexaMusic.utils.decorators.language import language

# Command
Expand Down Expand Up @@ -65,9 +67,7 @@ async def gbanuser(client, message: Message, _):
served_chats.append(int(chat["chat_id"]))
time_expected = len(served_chats)
time_expected = get_readable_time(time_expected)
mystic = await message.reply_text(
_["gban_5"].format(mention, time_expected)
)
mystic = await message.reply_text(_["gban_5"].format(mention, time_expected))
number_of_chats = 0
for chat_id in served_chats:
try:
Expand All @@ -78,9 +78,7 @@ async def gbanuser(client, message: Message, _):
except Exception:
pass
await add_banned_user(user_id)
await message.reply_text(
_["gban_6"].format(mention, number_of_chats)
)
await message.reply_text(_["gban_6"].format(mention, number_of_chats))
await mystic.delete()


Expand Down Expand Up @@ -108,9 +106,7 @@ async def gungabn(client, message: Message, _):
served_chats.append(int(chat["chat_id"]))
time_expected = len(served_chats)
time_expected = get_readable_time(time_expected)
mystic = await message.reply_text(
_["gban_8"].format(mention, time_expected)
)
mystic = await message.reply_text(_["gban_8"].format(mention, time_expected))
number_of_chats = 0
for chat_id in served_chats:
try:
Expand All @@ -121,9 +117,7 @@ async def gungabn(client, message: Message, _):
except Exception:
pass
await remove_banned_user(user_id)
await message.reply_text(
_["gban_9"].format(mention, number_of_chats)
)
await message.reply_text(_["gban_9"].format(mention, number_of_chats))
await mystic.delete()


Expand All @@ -141,9 +135,7 @@ async def gbanned_list(client, message: Message, _):
count += 1
try:
user = await app.get_users(user_id)
user = (
user.first_name if not user.mention else user.mention
)
user = user.first_name if not user.mention else user.mention
msg += f"{count}{user}\n"
except Exception:
msg += f"{count}➤ [Unfetched User]{user_id}\n"
Expand Down
106 changes: 36 additions & 70 deletions AlexaMusic/plugins/tools/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
# All rights reserved. © Alisha © Alexa © Yukki





import asyncio
import platform
from sys import version as pyver
Expand All @@ -30,18 +27,25 @@
from AlexaMusic.core.userbot import assistants
from AlexaMusic.misc import SUDOERS, pymongodb
from AlexaMusic.plugins import ALL_MODULES
from AlexaMusic.utils.database import (get_global_tops,
get_particulars, get_queries,
get_served_chats,
get_served_users, get_sudoers,
get_top_chats, get_topp_users)
from AlexaMusic.utils.database import (
get_global_tops,
get_particulars,
get_queries,
get_served_chats,
get_served_users,
get_sudoers,
get_top_chats,
get_topp_users,
)
from AlexaMusic.utils.decorators.language import language, languageCB
from AlexaMusic.utils.inline.stats import (back_stats_buttons,
back_stats_markup,
get_stats_markup,
overallback_stats_markup,
stats_buttons,
top_ten_stats_markup)
from AlexaMusic.utils.inline.stats import (
back_stats_buttons,
back_stats_markup,
get_stats_markup,
overallback_stats_markup,
stats_buttons,
top_ten_stats_markup,
)

loop = asyncio.get_running_loop()

Expand All @@ -51,16 +55,11 @@


@app.on_message(
filters.command(STATS_COMMAND)
& filters.group
& ~filters.edited
& ~BANNED_USERS
filters.command(STATS_COMMAND) & filters.group & ~filters.edited & ~BANNED_USERS
)
@language
async def stats_global(client, message: Message, _):
upl = stats_buttons(
_, True if message.from_user.id in SUDOERS else False
)
upl = stats_buttons(_, True if message.from_user.id in SUDOERS else False)
await message.reply_photo(
photo=config.STATS_IMG_URL,
caption=_["gstats_11"].format(config.MUSIC_BOT_NAME),
Expand All @@ -69,10 +68,7 @@ async def stats_global(client, message: Message, _):


@app.on_message(
filters.command(GSTATS_COMMAND)
& filters.group
& ~filters.edited
& ~BANNED_USERS
filters.command(GSTATS_COMMAND) & filters.group & ~filters.edited & ~BANNED_USERS
)
@language
async def gstats_global(client, message: Message, _):
Expand Down Expand Up @@ -121,9 +117,7 @@ def get_stats():
) = await YouTube.details(videoid, True)
title = title.title()
final = f"Top Most Played Track on {MUSIC_BOT_NAME}\n\n**Title:** {title}\n\nPlayed** {co} **times"
upl = get_stats_markup(
_, True if message.from_user.id in SUDOERS else False
)
upl = get_stats_markup(_, True if message.from_user.id in SUDOERS else False)
await app.send_photo(
message.chat.id,
photo=thumbnail,
Expand All @@ -146,9 +140,7 @@ async def top_users_ten(client, CallbackQuery: CallbackQuery, _):
pass
mystic = await CallbackQuery.edit_message_text(
_["gstats_3"].format(
f"of {CallbackQuery.message.chat.title}"
if what == "Here"
else what
f"of {CallbackQuery.message.chat.title}" if what == "Here" else what
)
)
if what == "Tracks":
Expand All @@ -167,11 +159,7 @@ async def top_users_ten(client, CallbackQuery: CallbackQuery, _):
def get_stats():
results = {}
for i in stats:
top_list = (
stats[i]
if what in ["Chats", "Users"]
else stats[i]["spot"]
)
top_list = stats[i] if what in ["Chats", "Users"] else stats[i]["spot"]
results[str(i)] = top_list
list_arranged = dict(
sorted(
Expand Down Expand Up @@ -207,17 +195,13 @@ def get_stats():
limit,
)
if what == "Tracks"
else _["gstats_7"].format(
len(stats), total_count, limit
)
else _["gstats_7"].format(len(stats), total_count, limit)
)
msg = temp + msg
return msg, list_arranged

try:
msg, list_arranged = await loop.run_in_executor(
None, get_stats
)
msg, list_arranged = await loop.run_in_executor(None, get_stats)
except Exception as e:
print(e)
return
Expand Down Expand Up @@ -247,9 +231,7 @@ def get_stats():
msg = temp + msg
med = InputMediaPhoto(media=config.GLOBAL_IMG_URL, caption=msg)
try:
await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.GLOBAL_IMG_URL, caption=msg, reply_markup=upl
Expand Down Expand Up @@ -305,9 +287,7 @@ async def overall_stats(client, CallbackQuery, _):
🌹 **ᴩʟᴀʏʟɪsᴛ ᴩʟᴀʏ ʟɪᴍɪᴛ:** {fetch_playlist}"""
med = InputMediaPhoto(media=config.STATS_IMG_URL, caption=text)
try:
await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.STATS_IMG_URL, caption=text, reply_markup=upl
Expand All @@ -318,9 +298,7 @@ async def overall_stats(client, CallbackQuery, _):
@languageCB
async def overall_stats(client, CallbackQuery, _):
if CallbackQuery.from_user.id not in SUDOERS:
return await CallbackQuery.answer(
"ᴏɴʟʏ ғᴏʀ sᴜᴅᴏ ᴜsᴇʀs.", show_alert=True
)
return await CallbackQuery.answer("ᴏɴʟʏ ғᴏʀ sᴜᴅᴏ ᴜsᴇʀs.", show_alert=True)
callback_data = CallbackQuery.data.strip()
what = callback_data.split(None, 1)[1]
if what != "s":
Expand All @@ -335,10 +313,7 @@ async def overall_stats(client, CallbackQuery, _):
sc = platform.system()
p_core = psutil.cpu_count(logical=False)
t_core = psutil.cpu_count(logical=True)
ram = (
str(round(psutil.virtual_memory().total / (1024.0**3)))
+ " GB"
)
ram = str(round(psutil.virtual_memory().total / (1024.0**3))) + " GB"
try:
cpu_freq = psutil.cpu_freq().current
if cpu_freq >= 1000:
Expand Down Expand Up @@ -408,18 +383,15 @@ async def overall_stats(client, CallbackQuery, _):
"""
med = InputMediaPhoto(media=config.STATS_IMG_URL, caption=text)
try:
await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.STATS_IMG_URL, caption=text, reply_markup=upl
)


@app.on_callback_query(
filters.regex(pattern=r"^(TOPMARKUPGET|GETSTATS|GlobalStats)$")
& ~BANNED_USERS
filters.regex(pattern=r"^(TOPMARKUPGET|GETSTATS|GlobalStats)$") & ~BANNED_USERS
)
@languageCB
async def back_buttons(client, CallbackQuery, _):
Expand All @@ -435,9 +407,7 @@ async def back_buttons(client, CallbackQuery, _):
caption=_["gstats_9"],
)
try:
await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.GLOBAL_IMG_URL,
Expand All @@ -454,9 +424,7 @@ async def back_buttons(client, CallbackQuery, _):
caption=_["gstats_10"].format(config.MUSIC_BOT_NAME),
)
try:
await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.GLOBAL_IMG_URL,
Expand All @@ -473,12 +441,10 @@ async def back_buttons(client, CallbackQuery, _):
caption=_["gstats_11"].format(config.MUSIC_BOT_NAME),
)
try:
await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.STATS_IMG_URL,
caption=_["gstats_11"].format(config.MUSIC_BOT_NAME),
reply_markup=upl,
)
)

0 comments on commit 40f62d3

Please sign in to comment.