Skip to content

Commit

Permalink
Update 11 files
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 8, 2023
1 parent 14cacbe commit 28bd472
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 46 deletions.
5 changes: 3 additions & 2 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from pytgcalls import GroupCallFactory
from bot.utils.driver import get_driver

VOICE_CHATS = {}
BOT_USERNAME = config.BOT_USERNAME

_logs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "logs")
_logs_file = os.path.join(_logs_dir, "kreacher.log")
if not os.path.exists(_logs_dir):
Expand All @@ -30,8 +33,6 @@
level=logging.INFO,
)

BOT_USERNAME = config.BOT_USERNAME

# Bot Client
kreacher = Client(
"bot.kreacher",
Expand Down
11 changes: 6 additions & 5 deletions bot/callbacks/streams.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os
from bot import kreacher
from pyrogram import filters, Client
from pyrogram.types import CallbackQuery
from bot.dbs.instances import VOICE_CHATS
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup

from bot import kreacher, VOICE_CHATS
from bot.helpers.pkl import load_pkl, dump_pkl
from bot.decorators.only_managers import only_managers
from bot.helpers.handler import next_item, skip_current
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup

current_dir = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(current_dir, "../dbs/queues.pkl")

_cwd = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(_cwd, "../dbs/queues.pkl")


@kreacher.on_callback_query(filters.regex("pause_or_resume"))
Expand Down
8 changes: 4 additions & 4 deletions bot/helpers/handler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from bot import VOICE_CHATS
from bot.helpers.pkl import load_pkl, dump_pkl
from bot.dbs.instances import VOICE_CHATS
from bot.helpers.queues import clear_queue, get_queue, pop_an_item

current_dir = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(current_dir, "../dbs/queues.pkl")
actives = os.path.join(current_dir, "../dbs/actives.pkl")
_cwd = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(_cwd, "../dbs/queues.pkl")
actives = os.path.join(_cwd, "../dbs/actives.pkl")


async def skip_current(chat):
Expand Down
1 change: 0 additions & 1 deletion bot/models/instances.py

This file was deleted.

3 changes: 1 addition & 2 deletions bot/plugins/commands/actives.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from bot import kreacher
from asyncio import sleep
from pyrogram.types import Message
from pyrogram import filters, Client
from bot.dbs.instances import VOICE_CHATS
from bot import kreacher, VOICE_CHATS
from bot.decorators.only_dev import only_dev


Expand Down
7 changes: 3 additions & 4 deletions bot/plugins/commands/join.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from bot import on_call, kreacher
from pyrogram.types import Message
from pyrogram import filters, Client
from bot.dbs.instances import VOICE_CHATS
from pyrogram import filters, client
from bot import on_call, kreacher, VOICE_CHATS
from bot.decorators.only_admins import only_admins
from bot.decorators.only_grps_chnns import only_grps_chnns

Expand All @@ -13,7 +12,7 @@ async def _(client: Client, message: Message):
try:
if VOICE_CHATS.get(message.chat.id) is not None:
raise Exception("Streaming is active")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await message.reply(
"**__Master, what do you need? \U0001f917 \n\nVoice Chat started successfully__** \u2728",
Expand Down
5 changes: 2 additions & 3 deletions bot/plugins/commands/leave.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from bot import kreacher
from pyrogram.types import message
from pyrogram import filters, Client
from pyrogram.types import Message
from bot.dbs.instances import VOICE_CHATS
from bot import kreacher, VOICE_CHATS
from bot.helpers.queues import clear_queue
from bot.decorators.only_admins import only_admins
from bot.decorators.only_grps_chnns import only_grps_chnns
Expand Down
17 changes: 8 additions & 9 deletions bot/plugins/commands/play_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import logging
from asyncio import sleep
from bot.helpers.tts import tts
from bot import kreacher, on_call
from bot import kreacher, on_call, VOICE_CHATS
from pyrogram.types import Message
from html.parser import HTMLParser
from pyrogram import filters, Client
from bot.helpers.progress import progress
from bot.dbs.instances import VOICE_CHATS
from bot.decorators.only_grps_chnns import only_grps_chnns
from ebooklib import epub as epublib, ITEM_IMAGE, ITEM_DOCUMENT
from bot.helpers.queues import (
Expand All @@ -20,16 +19,14 @@

# used to hide ebooklib annoying warnings
shutup.please()
c = os.path.dirname(os.path.abspath(__file__))
_cwd = os.path.dirname(os.path.abspath(__file__))


@kreacher.on_message(filters.regex(pattern="^[!?/]play_book"))
@only_grps_chnns
async def _(client: Client, message: Message):
text = ""
h = _HTMLFilter()
book = os.path.join(c, f"../../downloads/books/{str(uuid.uuid4())}.pdf")
audiobook = os.path.join(c, f"../../tmp/{str(uuid.uuid4())}.wav")
try:
if not message.reply_to_message:
return await message.reply(
Expand All @@ -38,11 +35,13 @@ async def _(client: Client, message: Message):
msg = await message.reply("\u23F3 **__Processing...__**")
await sleep(2)
file_type = message.reply_to_message.document.mime_type.split("/", 1)[1]
book = os.path.join(c, f"../../downloads/books/{str(uuid.uuid4())}.{file_type}")

file_name = os.path.join(
_cwd, f"../../downloads/books/{str(uuid.uuid4())}.{file_type}"
)
audiobook = os.path.join(_cwd, f"../../tmp/{str(uuid.uuid4())}.wav")
await msg.edit("💾 **__Downloading...__**")
f = await message.reply_to_message.download(
file_name=book,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat, msg),
)
Expand Down Expand Up @@ -84,7 +83,7 @@ async def _(client: Client, message: Message):
await sleep(2)
if VOICE_CHATS.get(message.chat.id) is None:
await msg.edit("🪄 **__Joining the voice chat...__**")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await sleep(2)
await on_call.start_audio(audiobook, repeat=False)
Expand Down
15 changes: 7 additions & 8 deletions bot/plugins/commands/play_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from pyrogram.types import Message
from bot.helpers.pkl import load_pkl
from bot.helpers.user_info import user_info
from bot import kreacher, on_call
from bot import kreacher, on_call, VOICE_CHATS
from bot.helpers.progress import progress
from bot.helpers.yt import ytsearch, ytdl
from bot.dbs.instances import VOICE_CHATS
from pyrogram.enums.chat_type import ChatType
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from bot.helpers.queues import (
Expand All @@ -22,15 +21,15 @@
ngantri = "https://telegra.ph/file/b6402152be44d90836339.jpg"
owner = "1669178360"

c = os.path.dirname(os.path.abspath(__file__))
_cwd = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(c, "../../dbs/queues.pkl")


@kreacher.on_message(filters.regex(pattern="^[!?/]play_song"))
async def _(client: Client, message: Message):
QUEUE = await load_pkl(queues, "rb", "dict")
data = await user_info(message.from_user)
download_as = os.path.join(c, f"../../downloads/songs/{str(uuid.uuid4())}.mp3")
file_name = os.path.join(_cwd, f"../../downloads/songs/{str(uuid.uuid4())}.mp3")
if message.chat.type == ChatType.PRIVATE:
return await message.reply(
"**__Mr. Wizard, this command can only be used in groups or channels__** \U0001f937\U0001f3fb\u200D\u2642\uFE0F"
Expand Down Expand Up @@ -97,7 +96,7 @@ async def _(client: Client, message: Message):
)
if VOICE_CHATS.get(message.chat.id) is None:
await msg.edit("🪄 **__Joining the voice chat...__**")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await sleep(2)
await on_call.start_audio(url, repeat=False)
Expand Down Expand Up @@ -127,7 +126,7 @@ async def _(client: Client, message: Message):
await msg.edit("💾 **__Downloading...__**")
media = await client.download_media(
message.reply_to_message.audio,
file_name=download_as,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat, msg),
)
Expand All @@ -136,7 +135,7 @@ async def _(client: Client, message: Message):
await msg.edit("💾 **__Downloading...__**")
media = await client.download_media(
message.reply_to_message.voice,
file_name=download_as,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat, msg),
)
Expand Down Expand Up @@ -169,7 +168,7 @@ async def _(client: Client, message: Message):
)
if VOICE_CHATS.get(message.chat.id) is None:
await msg.edit("🪄 **__Joining the voice chat...__**")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await sleep(2)
await on_call.start_audio(media, repeat=False)
Expand Down
9 changes: 4 additions & 5 deletions bot/plugins/commands/play_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from pyrogram.types import Message
from bot.helpers.pkl import load_pkl
from bot.helpers.user_info import user_info
from bot import assistant, kreacher, on_call
from bot.dbs.instances import VOICE_CHATS
from bot import assistant, kreacher, on_call, VOICE_CHATS
from bot.helpers.progress import progress
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from bot.helpers.yt import ytdl, ytsearch
Expand All @@ -22,7 +21,7 @@

_cwd = os.path.dirname(os.path.abspath(__file__))

queues = os.path.join(c, "../../dbs/queues.pkl")
queues = os.path.join(_cwd, "../../dbs/queues.pkl")


@kreacher.on_message(filters.regex(pattern="^[!?/]play_video"))
Expand Down Expand Up @@ -101,7 +100,7 @@ async def _(client: Client, message: Message):
)
if VOICE_CHATS.get(message.chat.id) is None:
await msg.edit("🪄 **__Joining the voice chat...__**")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await sleep(2)
await on_call.start_video(
Expand Down Expand Up @@ -141,7 +140,7 @@ async def _(client: Client, message: Message):
)
if VOICE_CHATS.get(message.chat.id) is None:
await msg.edit("**__Joining the voice chat...__** \u23F3")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await sleep(2)
await on_call.start_video(media, with_audio=True, repeat=False)
Expand Down
5 changes: 2 additions & 3 deletions bot/plugins/commands/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from pyrogram import filters, Client
from pyrogram.enums import MessagesFilter
from bot.helpers.progress import progress
from bot.dbs.instances import VOICE_CHATS
from bot import assistant, kreacher, on_call
from bot.scrapers.images import ImageScraper
from bot import assistant, kreacher, on_call, VOICE_CHATS
from bot.decorators.only_grps_chnns import only_grps_chnns
from bot.helpers.queues import (
clear_queue,
Expand Down Expand Up @@ -95,7 +94,7 @@ async def _(client: Client, message: Message):
)
if VOICE_CHATS.get(message.chat.id) is None:
await msg.edit("🪄 **__Joining the voice chat...__**")
await on_call.join(message.chat.id)
await on_call.start(message.chat.id)
VOICE_CHATS[message.chat.id] = on_call
await sleep(2)
await on_call.start_video(
Expand Down

0 comments on commit 28bd472

Please sign in to comment.