Skip to content

Commit

Permalink
refactor: modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmaialva33 committed Oct 25, 2024
1 parent d51c8f4 commit 2a45882
Show file tree
Hide file tree
Showing 50 changed files with 586 additions and 653 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.winx.env
.cache
Winxlogs.txt
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion WinxMusic/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ async def stop(self):
LOGGER(__name__).info("Bot is shutting down")
await self.send_message(
config.LOG_GROUP_ID,
text=f"🛑<u><b>{self.mention} Bot Desligado :</b></u>\n\n🆔 Id: <code>{self.id}</code>\n📛 Nome: {self.name}\n🔗 Nome de usuário: @{self.username}",
text=f"🛑 <u><b>{self.mention} Bot Desligado :</b></u>\n\n🆔 Id: <code>{self.id}</code>\n📛 Nome: {self.name}\n🔗 Nome de usuário: @{self.username}",
)
await super().stop()
22 changes: 11 additions & 11 deletions WinxMusic/core/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ async def force_stop_stream(self, chat_id: int):
pass

async def skip_stream(
self,
chat_id: int,
link: str,
video: Union[bool, str] = None,
image: Union[bool, str] = None,
self,
chat_id: int,
link: str,
video: Union[bool, str] = None,
image: Union[bool, str] = None,
):
assistant = await group_assistant(self, chat_id)
audio_stream_quality = await get_audio_bitrate(chat_id)
Expand Down Expand Up @@ -159,12 +159,12 @@ async def stream_call(self, link):
await assistant.leave_call(config.LOG_GROUP_ID)

async def join_call(
self,
chat_id: int,
original_chat_id: int,
link,
video: Union[bool, str] = None,
image: Union[bool, str] = None,
self,
chat_id: int,
original_chat_id: int,
link,
video: Union[bool, str] = None,
image: Union[bool, str] = None,
):
assistant = await group_assistant(self, chat_id)
audio_stream_quality = await get_audio_bitrate(chat_id)
Expand Down
2 changes: 1 addition & 1 deletion WinxMusic/platforms/Carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self):

async def generate(self, text: str, user_id):
async with aiohttp.ClientSession(
headers={"Content-Type": "application/json"},
headers={"Content-Type": "application/json"},
) as ses:
params = {
"code": text,
Expand Down
46 changes: 23 additions & 23 deletions WinxMusic/platforms/Telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):

async def send_split_text(self, message, string):
n = self.chars_limit
out = [(string[i : i + n]) for i in range(0, len(string), n)]
out = [(string[i: i + n]) for i in range(0, len(string), n)]
j = 0
for x in out:
if j <= 2:
Expand Down Expand Up @@ -61,28 +61,28 @@ async def get_duration(self, file: Union[Video, Voice, Message]):
return dur

async def get_filepath(
self,
audio: Union[Voice, Message, bool, str] = None,
video: Union[Video, Message, bool, str] = None,
self,
audio: Union[Voice, Message, bool, str] = None,
video: Union[Video, Message, bool, str] = None,
):
if audio:
try:
file_name = (
audio.file_unique_id
+ "."
+ (
(audio.file_name.split(".")[-1])
if (not isinstance(audio, Voice))
else "ogg"
)
audio.file_unique_id
+ "."
+ (
(audio.file_name.split(".")[-1])
if (not isinstance(audio, Voice))
else "ogg"
)
)
except:
file_name = audio.file_unique_id + "." + ".ogg"
file_name = os.path.join(os.path.realpath("downloads"), file_name)
if video:
try:
file_name = (
video.file_unique_id + "." + (video.file_name.split(".")[-1])
video.file_unique_id + "." + (video.file_name.split(".")[-1])
)
except:
file_name = video.file_unique_id + "." + "mp4"
Expand All @@ -96,20 +96,20 @@ async def is_streamable_url(self, url: str) -> bool:
if response.status == 200:
content_type = response.headers.get("Content-Type", "")
if (
"application/vnd.apple.mpegurl" in content_type
or "application/x-mpegURL" in content_type
"application/vnd.apple.mpegurl" in content_type
or "application/x-mpegURL" in content_type
):
return True
if any(
keyword in content_type
for keyword in [
"audio",
"video",
"mp4",
"mpegurl",
"m3u8",
"mpeg",
]
keyword in content_type
for keyword in [
"audio",
"video",
"mp4",
"mpegurl",
"m3u8",
"mpeg",
]
):
return True
if url.endswith((".m3u8", ".index", ".mp4", ".mpeg", ".mpd")):
Expand Down
30 changes: 15 additions & 15 deletions WinxMusic/platforms/Youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def cookies():


def get_ytdl_options(
ytdl_opts: Union[str, dict, list], commandline: bool = True
ytdl_opts: Union[str, dict, list], commandline: bool = True
) -> Union[str, dict, list]:
token_data = os.getenv("TOKEN_DATA")

Expand Down Expand Up @@ -114,7 +114,7 @@ async def url(self, message_1: Message) -> Union[str, None]:
return entity.url
if offset in (None,):
return None
return text[offset : offset + length]
return text[offset: offset + length]

async def details(self, link: str, videoid: Union[bool, str] = None):
if videoid:
Expand Down Expand Up @@ -269,10 +269,10 @@ async def formats(self, link: str, videoid: Union[bool, str] = None):
return formats_available, link

async def slider(
self,
link: str,
query_type: int,
videoid: Union[bool, str] = None,
self,
link: str,
query_type: int,
videoid: Union[bool, str] = None,
):
if videoid:
link = self.base + link
Expand All @@ -287,15 +287,15 @@ async def slider(
return title, duration_min, thumbnail, vidid

async def download(
self,
link: str,
mystic,
video: Union[bool, str] = None,
videoid: Union[bool, str] = None,
songaudio: Union[bool, str] = None,
songvideo: Union[bool, str] = None,
format_id: Union[bool, str] = None,
title: Union[bool, str] = None,
self,
link: str,
mystic,
video: Union[bool, str] = None,
videoid: Union[bool, str] = None,
songaudio: Union[bool, str] = None,
songvideo: Union[bool, str] = None,
format_id: Union[bool, str] = None,
title: Union[bool, str] = None,
) -> str:
if videoid:
link = self.base + link
Expand Down
6 changes: 3 additions & 3 deletions WinxMusic/plugins/admins/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
get_authuser_names,
save_authuser,
)
from WinxMusic.utils.decorators import AdminActual, language
from WinxMusic.utils.decorators import admin_actual, language
from WinxMusic.utils.formatters import int_to_alpha
from config import BANNED_USERS, adminlist
from strings import command, get_command
Expand All @@ -19,7 +19,7 @@


@app.on_message(filters.command(AUTH_COMMAND) & filters.group & ~BANNED_USERS)
@AdminActual
@admin_actual
async def auth(_client: Client, message: Message, _):
if not message.reply_to_message:
if len(message.command) != 2:
Expand Down Expand Up @@ -81,7 +81,7 @@ async def auth(_client: Client, message: Message, _):


@app.on_message(filters.command(UNAUTH_COMMAND) & filters.group & ~BANNED_USERS)
@AdminActual
@admin_actual
async def unauthusers(_client: Client, message: Message, _):
if not message.reply_to_message:
if len(message.command) != 2:
Expand Down
26 changes: 13 additions & 13 deletions WinxMusic/plugins/admins/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from WinxMusic.core.call import Winx
from WinxMusic.misc import SUDOERS, db
from WinxMusic.utils import time_to_seconds
from WinxMusic.utils.channelplay import get_channeplayCB
from WinxMusic.utils.channelplay import get_channeplay_cb
from WinxMusic.utils.database import (
is_active_chat,
is_music_playing,
Expand All @@ -20,8 +20,8 @@
mute_on,
set_loop,
)
from WinxMusic.utils.decorators import ActualAdminCB
from WinxMusic.utils.decorators.language import languageCB
from WinxMusic.utils.decorators import actual_admin_cb
from WinxMusic.utils.decorators.language import language_cb
from WinxMusic.utils.formatters import seconds_to_min
from WinxMusic.utils.inline.play import (
livestream_markup,
Expand Down Expand Up @@ -53,7 +53,7 @@


@app.on_callback_query(filters.regex("PanelMarkup") & ~BANNED_USERS)
@languageCB
@language_cb
async def markup_panel(client, CallbackQuery: CallbackQuery, _):
await CallbackQuery.answer()
callback_data = CallbackQuery.data.strip()
Expand All @@ -73,7 +73,7 @@ async def markup_panel(client, CallbackQuery: CallbackQuery, _):


@app.on_callback_query(filters.regex("MainMarkup") & ~BANNED_USERS)
@languageCB
@language_cb
async def del_back_playlist(client, CallbackQuery, _):
await CallbackQuery.answer()
callback_data = CallbackQuery.data.strip()
Expand All @@ -96,7 +96,7 @@ async def del_back_playlist(client, CallbackQuery, _):


@app.on_callback_query(filters.regex("Pages") & ~BANNED_USERS)
@languageCB
@language_cb
async def del_back_playlist(client, CallbackQuery, _):
await CallbackQuery.answer()
callback_data = CallbackQuery.data.strip()
Expand Down Expand Up @@ -127,7 +127,7 @@ async def del_back_playlist(client, CallbackQuery, _):


@app.on_callback_query(filters.regex("ADMIN") & ~BANNED_USERS)
@languageCB
@language_cb
async def del_back_playlist(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
Expand Down Expand Up @@ -447,7 +447,7 @@ async def del_back_playlist(client, CallbackQuery, _):


@app.on_callback_query(filters.regex("MusicStream") & ~BANNED_USERS)
@languageCB
@language_cb
async def play_music(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
Expand All @@ -458,7 +458,7 @@ async def play_music(client, CallbackQuery, _):
except:
return
try:
chat_id, channel = await get_channeplayCB(_, cplay, CallbackQuery)
chat_id, channel = await get_channeplay_cb(_, cplay, CallbackQuery)
except:
return
user_name = CallbackQuery.from_user.first_name
Expand Down Expand Up @@ -527,7 +527,7 @@ async def anonymous_check(client, CallbackQuery):


@app.on_callback_query(filters.regex("WinxPlaylists") & ~BANNED_USERS)
@languageCB
@language_cb
async def play_playlists_command(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
Expand All @@ -545,7 +545,7 @@ async def play_playlists_command(client, CallbackQuery, _):
except:
return
try:
chat_id, channel = await get_channeplayCB(_, cplay, CallbackQuery)
chat_id, channel = await get_channeplay_cb(_, cplay, CallbackQuery)
except:
return
user_name = CallbackQuery.from_user.first_name
Expand Down Expand Up @@ -614,7 +614,7 @@ async def play_playlists_command(client, CallbackQuery, _):


@app.on_callback_query(filters.regex("slider") & ~BANNED_USERS)
@languageCB
@language_cb
async def slider_queries(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
Expand Down Expand Up @@ -687,7 +687,7 @@ async def close_menu(_, CallbackQuery):


@app.on_callback_query(filters.regex("stop_downloading") & ~BANNED_USERS)
@ActualAdminCB
@actual_admin_cb
async def stop_download(client, CallbackQuery: CallbackQuery, _):
message_id = CallbackQuery.message.id
task = lyrical.get(message_id)
Expand Down
4 changes: 2 additions & 2 deletions WinxMusic/plugins/admins/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from WinxMusic import app
from WinxMusic.utils.database.memorydatabase import get_loop, set_loop
from WinxMusic.utils.decorators import AdminRightsCheck
from WinxMusic.utils.decorators import admin_rights_check
from config import BANNED_USERS
from strings import get_command

LOOP_COMMAND = get_command("LOOP_COMMAND")


@app.on_message(filters.command(LOOP_COMMAND) & filters.group & ~BANNED_USERS)
@AdminRightsCheck
@admin_rights_check
async def admins(cli, message: Message, _, chat_id):
usage = _["admin_24"]
if len(message.command) != 2:
Expand Down
4 changes: 2 additions & 2 deletions WinxMusic/plugins/admins/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from WinxMusic import app
from WinxMusic.core.call import Winx
from WinxMusic.utils.database import is_music_playing, music_off
from WinxMusic.utils.decorators import AdminRightsCheck
from WinxMusic.utils.decorators import admin_rights_check
from config import BANNED_USERS
from strings import get_command

PAUSE_COMMAND = get_command("PAUSE_COMMAND")


@app.on_message(filters.command(PAUSE_COMMAND) & filters.group & ~BANNED_USERS)
@AdminRightsCheck
@admin_rights_check
async def pause_admin(cli, message: Message, _, chat_id):
if not len(message.command) == 1:
return await message.reply_text(_["general_2"])
Expand Down
4 changes: 2 additions & 2 deletions WinxMusic/plugins/admins/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from WinxMusic import app
from WinxMusic.core.call import Winx
from WinxMusic.utils.database import is_music_playing, music_on
from WinxMusic.utils.decorators import AdminRightsCheck
from WinxMusic.utils.decorators import admin_rights_check
from config import BANNED_USERS
from strings import get_command

RESUME_COMMAND = get_command("RESUME_COMMAND")


@app.on_message(filters.command(RESUME_COMMAND) & filters.group & ~BANNED_USERS)
@AdminRightsCheck
@admin_rights_check
async def resume_com(cli, message: Message, _, chat_id):
if not len(message.command) == 1:
return await message.reply_text(_["general_2"])
Expand Down
Loading

0 comments on commit 2a45882

Please sign in to comment.