Skip to content

Commit

Permalink
Update 5 files
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Aug 5, 2023
1 parent 5060f07 commit 4c688d8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
4 changes: 3 additions & 1 deletion tlg_bot/kreacher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
BOT_USERNAME = config.BOT_USERNAME
ASSISTANT_ID = config.ASSISTANT_ID

client = TelegramClient(None, api_id=config.API_ID, api_hash=config.API_HASH)
kreacher = TelegramClient(None, api_id=config.API_ID, api_hash=config.API_HASH)
_factory = GroupCallFactory(kreacher, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON)
_factory = GroupCallFactory(client, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON)
ins = _factory.get_group_call()
client.start()
kreacher.start(bot_token=config.BOT_TOKEN)
11 changes: 6 additions & 5 deletions tlg_bot/kreacher/plugins/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kreacher import kreacher
from kreacher.helpers.voice_chats import get_voice_chat
from kreacher.helpers.voice_chats import VOICE_CHATS
from telethon import events


Expand All @@ -11,19 +11,20 @@ async def _(event):
@kreacher.on(events.callbackquery.CallbackQuery(data="pause_callback"))
async def _(event):
chat = await event.get_chat()
proto = get_voice_chat(chat)
proto = VOICE_CHATS[chat.id]
await proto.set_pause(True)


@kreacher.on(events.callbackquery.CallbackQuery(data="resume_callback"))
async def _(event):
chat = await event.get_chat()
proto = get_voice_chat(chat)
proto = VOICE_CHATS[chat.id]
await proto.set_pause(False)


@kreacher.on(events.callbackquery.CallbackQuery(data="end_callback"))
async def _(event):
chat = await event.get_chat()
proto = get_voice_chat(chat)
await proto.stop_media()
proto = VOICE_CHATS[chat.id]
await proto.stop_media()
VOICE_CHATS.pop(chat.id)
5 changes: 3 additions & 2 deletions tlg_bot/kreacher/plugins/leave.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from kreacher import kreacher
from kreacher.helpers.voice_chats import get_voice_chat
from kreacher.helpers.voice_chats import VOICE_CHATS
from telethon import events


@kreacher.on(events.NewMessage(pattern="[!?/]leave"))
async def leave_handler(event):
try:
chat = await event.get_chat()
proto = get_voice_chat(chat)
proto = VOICE_CHATS[chat.id]
if proto is None:
raise Exception("Streaming is not active")
await proto.leave_current_group_call()
VOICE_CHATS.pop(chat.id)
await event.reply("<i>Goodbye master, just call me if you need me. \n\nVoice Chat left successfully.</i>", parse_mode="HTML")
except Exception as e:
return await event.reply(f"<i>Oops master, something wrong has happened. \n\nError:</i> <code>{e}</code>", parse_mode="HTML")
6 changes: 3 additions & 3 deletions tlg_bot/kreacher/plugins/new.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from kreacher import ins, kreacher
from kreacher.helpers.voice_chats import get_voice_chat, start_voice_chat
from kreacher.helpers.voice_chats import VOICE_CHATS
from telethon import events


@kreacher.on(events.NewMessage(pattern="[!?/]new"))
async def new_handler(event):
try:
chat = await event.get_chat()
proto = get_voice_chat(chat)
proto = VOICE_CHATS[chat.id]
if proto is not None:
raise Exception("Streaming is active")
start_voice_chat(chat, ins)
await ins.start(chat.id)
VOICE_CHATS[chat.id] = ins
await event.reply("<i>Master, what do you need? \n\nVoice Chat joined successfully.</i>", parse_mode="HTML")
except Exception as e:
return await event.reply(f"<i>Oops master, something wrong has happened. \n\nError:</i> <code>{e}</code>", parse_mode="HTML")
26 changes: 12 additions & 14 deletions tlg_bot/kreacher/plugins/play_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from youtubesearchpython import VideosSearch
from kreacher import ins, kreacher
from kreacher.helpers.queues import QUEUE, get_queue
from kreacher.helpers.voice_chats import start_voice_chat, get_voice_chat, stop_voice_chat
from kreacher.helpers.voice_chats import VOICE_CHATS
from telethon import Button, events
from asyncio import sleep
from yt_dlp import YoutubeDL
Expand Down Expand Up @@ -32,10 +32,8 @@ async def play_video(event):
return await msg.edit("❗ __Send Me An Live Stream Link / YouTube Video Link / Reply To An Video To Start Video Streaming!__")
regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"
match = re.match(regex, url)
proto = get_voice_chat(chat)
if proto is None:
if VOICE_CHATS[chat.id] is None:
await msg.edit("<i>Joining the voice chat...</i>", parse_mode="HTML")
start_voice_chat(chat, ins)
if match:
await msg.edit("🔄 <i>Starting YouTube Video Stream...</i>", parse_mode="HTML")
try:
Expand All @@ -53,8 +51,8 @@ async def play_video(event):
except Exception as e:
await msg.edit(f"❌ <i>Master, YouTube Download Error!</i> \n\n<code>Error: {e}</code>", parse_mode="HTML")
print(e)
stop_voice_chat(chat)
return await proto.stop()
VOICE_CHATS.pop(chat.id)
return await VOICE_CHATS[chat.id].stop()

else:
await msg.edit("🔄 <i>Starting Live Video Stream...</i>", parse_mode="HTML")
Expand All @@ -64,6 +62,7 @@ async def play_video(event):
try:
await sleep(2)
await ins.start(chat.id)
VOICE_CHATS[chat.id] = ins
await ins.start_video(link, with_audio=True, repeat=False)
await msg.delete()
await event.reply(
Expand All @@ -78,8 +77,8 @@ async def play_video(event):
)
except Exception as e:
await msg.edit(f"❌ **An Error Occoured !** \n\nError: `{e}`")
stop_voice_chat(chat)
return await proto.stop()
VOICE_CHATS.pop(chat.id)
return await VOICE_CHATS[chat.id].stop()

elif media.video or media.file:
await msg.edit("🔄 `Downloading ...`")
Expand All @@ -95,6 +94,7 @@ async def play_video(event):
try:
await sleep(2)
await ins.start(chat.id)
VOICE_CHATS[chat.id] = ins
await ins.start_video(video, with_audio=True, repeat=False)
await msg.delete()
await event.reply(
Expand All @@ -110,8 +110,8 @@ async def play_video(event):
except Exception as e:
await msg.edit(f"❌ <i>An Error Occoured!</i> \n\n<code>Error: {e}</code>", parse_mode="HTML")
print(e)
await stop_voice_chat(chat)
return await proto.stop()
VOICE_CHATS.pop(chat.id)
return await VOICE_CHATS[chat.id].stop()

else:
await msg.edit("<code>\U0001F9D9 Do you want to search for a YouTube video?</code>", parse_mode="HTML")
Expand Down Expand Up @@ -158,9 +158,8 @@ async def pause(event, perm):
)
return
if chat.id in QUEUE:
proto = get_voice_chat(chat)
try:
await proto.pause_stream(chat.id)
await VOICE_CHATS[chat.id].pause_stream(chat.id)
await event.reply("**Streaming Paused**")
except Exception as e:
await event.reply(f"**ERROR:** `{e}`")
Expand All @@ -178,9 +177,8 @@ async def resume(event, perm):
)
return
if chat.id in QUEUE:
proto = get_voice_chat(chat)
try:
await proto.resume_stream(chat.id)
await VOICE_CHATS[chat.id].resume_stream(chat.id)
await event.reply("**Streaming Started Back 🔙**")
except Exception as e:
await event.reply(f"**ERROR:** `{e}`")
Expand Down

0 comments on commit 4c688d8

Please sign in to comment.