Skip to content

Commit

Permalink
Update 17 files
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Aug 6, 2023
1 parent f86b942 commit b5eaf9b
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 114 deletions.
6 changes: 3 additions & 3 deletions tlg_bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
import telethon
import glob
from pathlib import Path
from kreacher.utils import load_plugins
from tlg_bot.utils import load_plugins
import logging
from termcolor import colored
from kreacher import kreacher
from tlg_bot import kreacher


logging.basicConfig(
format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s",
level=logging.INFO,
)

path = "kreacher/plugins/*.py"
path = "tlg_bot/plugins/*.py"
files = glob.glob(path)
for name in files:
with open(name) as a:
Expand Down
2 changes: 1 addition & 1 deletion tlg_bot/helpers/find_movie.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from kreacher import config, kreacher
from tlg_bot import config, kreacher
from telethon import events
from telethon.tl.functions.messages import SearchRequest
from telethon.tl.types import InputMessagesFilterVideo
Expand Down
2 changes: 1 addition & 1 deletion tlg_bot/helpers/queues.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from kreacher.dicts.dicts import QUEUE
from tlg_bot.dicts.dicts import QUEUE

active = []

Expand Down
4 changes: 2 additions & 2 deletions tlg_bot/helpers/queues_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kreacher.dicts.dicts import QUEUE, VOICE_CHATS
from kreacher.helpers.queues import (
from tlg_bot.dicts.dicts import QUEUE, VOICE_CHATS
from tlg_bot.helpers.queues import (
clear_queue,
get_queue,
pop_an_item,
Expand Down
2 changes: 1 addition & 1 deletion tlg_bot/helpers/yt_dlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import os.path
from yt_dlp import YoutubeDL
from kreacher import kreacher as bot
from tlg_bot import kreacher as bot
from telethon.tl.functions.channels import GetParticipantRequest
from telethon.tl.types import (
ChannelParticipantAdmin,
Expand Down
12 changes: 5 additions & 7 deletions tlg_bot/plugins/actives.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from asyncio import sleep
from telethon import events
from kreacher import kreacher
from kreacher.dicts.dicts import VOICE_CHATS
from tlg_bot import kreacher
from tlg_bot.dicts.dicts import VOICE_CHATS


@kreacher.on(events.NewMessage(pattern="[!?/]actives"))
async def actives(event):
msg = await event.reply(
"<i>Getting active Voice Chats... \n\nPlease hold, master</i>",
parse_mode="HTML",
"__Getting active Voice Chats... \n\nPlease hold, master__",
)
await sleep(3)
served_chats = len(VOICE_CHATS)
if served_chats > 0:
return await msg.edit(
f"<i>Active Voice Chats: </i><b>{served_chats}</b>",
parse_mode="HTML",
f"__Active Voice Chats:__ **{served_chats}**",
)

return await msg.edit("<i>No active Voice Chats</i>", parse_mode="HTML")
return await msg.edit("__No active Voice Chats__")
3 changes: 1 addition & 2 deletions tlg_bot/plugins/admins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from telethon import events, Button
from kreacher import kreacher
from kreacher.status import *
from tlg_bot import kreacher


@kreacher.on(events.callbackquery.CallbackQuery(data="admin"))
Expand Down
12 changes: 5 additions & 7 deletions tlg_bot/plugins/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asyncio import sleep
from kreacher import config, kreacher
from kreacher.dicts.dicts import QUEUE, VOICE_CHATS
from tlg_bot import config, kreacher
from tlg_bot.dicts.dicts import QUEUE, VOICE_CHATS
from telethon import events, Button
from kreacher.helpers.queues_handler import next_item, skip_current
from tlg_bot.helpers.queues_handler import next_item, skip_current

thumb = "https://telegra.ph/file/3e14128ad5c9ec47801bd.jpg"

Expand All @@ -20,7 +20,7 @@ async def _(event):
if VOICE_CHATS[chat.id].is_video_paused:
await VOICE_CHATS[chat.id].set_pause(False)
await event.edit(
"\U00002378 <i>Started Video Streaming!</i>",
"\U00002378 __Started Video Streaming!__",
file=thumb,
buttons=[
[
Expand All @@ -32,12 +32,11 @@ async def _(event):
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML",
)
return await sleep(3)
await VOICE_CHATS[chat.id].set_pause(True)
await event.edit(
"\U00002378 <i>Started Video Streaming!</i>",
"\U00002378 __Started Video Streaming!__",
file=thumb,
buttons=[
[
Expand All @@ -47,7 +46,6 @@ async def _(event):
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML",
)
return await sleep(3)

Expand Down
2 changes: 1 addition & 1 deletion tlg_bot/plugins/help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from telethon import events, Button
from kreacher import kreacher, config
from tlg_bot import kreacher, config


@kreacher.on(events.NewMessage(pattern="[!?/]help"))
Expand Down
10 changes: 4 additions & 6 deletions tlg_bot/plugins/leave.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kreacher import kreacher
from kreacher.dicts.dicts import VOICE_CHATS
from tlg_bot import kreacher
from tlg_bot.dicts.dicts import VOICE_CHATS
from telethon import events


Expand All @@ -12,11 +12,9 @@ async def leave_handler(event):
await VOICE_CHATS[chat.id].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",
"__Goodbye master, just call me if you need me. \n\nVoice Chat left successfully.__",
)
except Exception as e:
return await event.reply(
f"<i>Oops master, something wrong has happened.</i> \n\n<code>Error: {e}</code>",
parse_mode="HTML",
f"__Oops master, something wrong has happened.__ \n\n`Error: {e}`",
)
10 changes: 4 additions & 6 deletions tlg_bot/plugins/new.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kreacher import ins, kreacher
from kreacher.dicts.dicts import VOICE_CHATS
from tlg_bot import ins, kreacher
from tlg_bot.dicts.dicts import VOICE_CHATS
from telethon import events


Expand All @@ -12,11 +12,9 @@ async def new_handler(event):
await ins.start(chat.id)
VOICE_CHATS[chat.id] = ins
await event.reply(
"<i>Master, what do you need? \n\nVoice Chat started successfully.</i>",
parse_mode="HTML",
"__Master, what do you need? \n\nVoice Chat started successfully.__",
)
except Exception as e:
return await event.reply(
f"<i>Oops master, something wrong has happened.</i> \n\n<code>Error: {e}</code>",
parse_mode="HTML",
f"__Oops master, something wrong has happened.__ \n\n`Error: {e}`",
)
5 changes: 2 additions & 3 deletions tlg_bot/plugins/ping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from time import time
from datetime import datetime
from telethon import events
from kreacher import kreacher
from tlg_bot import kreacher


START_TIME = datetime.utcnow()
Expand Down Expand Up @@ -35,6 +35,5 @@ async def _(event):
uptime_sec = (current_time - START_TIME).total_seconds()
uptime = await _human_time_duration(int(uptime_sec))
await event.reply(
f"<i>Haha my master, PONG\n\n {delta_ping * 1000:.3f}\n\n {uptime}</i>",
parse_mode="HTML",
f"__Haha my master, PONG\n\n {delta_ping * 1000:.3f}ms.\n\n Running {uptime}.__",
)
46 changes: 20 additions & 26 deletions tlg_bot/plugins/play_song.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from asyncio import sleep
from kreacher.helpers.thumbnail import gen_thumb
from tlg_bot.helpers.thumbnail import gen_thumb
from telethon import Button, events
from kreacher.dicts.dicts import QUEUE, VOICE_CHATS
from kreacher.helpers.queues import (
from tlg_bot.dicts.dicts import QUEUE, VOICE_CHATS
from tlg_bot.helpers.queues import (
add_to_queue,
clear_queue,
)
from kreacher.helpers.yt_dlp import bash
from kreacher import config, ins, kreacher
from tlg_bot.helpers.yt_dlp import bash
from tlg_bot import config, ins, kreacher
from telethon.tl import types
from telethon.utils import get_display_name
from youtubesearchpython import VideosSearch
Expand Down Expand Up @@ -47,12 +48,14 @@ async def ytdl(format: str, link: str):
return 0, stderr


@kreacher.on(events.NewMessage(pattern="[!?/]play_song"))
@kreacher.on(events.NewMessage(pattern="^[!?/]play_song"))
async def play_song(event):
title = " ".join(event.text[5:])
replied = await event.get_reply_message()
chat = await event.get_chat()
msg = await event.reply("🔄 <i>Processing...</i>", parse_mode="HTML")
msg = await event.reply("🔄 **__Processing...__**")
dir = os.path.dirname(os.path.abspath(__file__))
downloads_dir = os.path.join(dir, "../downloads/songs")
from_user = vcmention(event.sender)
if (
replied
Expand All @@ -63,18 +66,16 @@ async def play_song(event):
and not title
):
return await msg.edit(
"<b>Give me your query which you want to play\n\n Example:</b> <code>/play Nira Ishq Bass boosted</code>",
"__Give me your query which you want to play\n\n Example:__ `/play Hey Boy Sia`",
file=config.CMD_IMG,
buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]],
parse_mode="HTML",
)
elif replied and not replied.audio and not replied.voice or not replied:
query = event.text.split(maxsplit=1)[1]
search = ytsearch(query)
if search == 0:
await msg.edit(
"<i>Can't find song.\n\nTry searching with more specific title.",
parse_mode="HTML",
"__Can't find song.\n\nTry searching with more specific title.__",
)
else:
name = search[0]
Expand All @@ -90,22 +91,19 @@ async def play_song(event):
elif chat.id in QUEUE:
pos = add_to_queue(chat, name, url, ref, "audio")
await msg.edit(
f"<b>Added to queue at {pos}\n\n Title: [{name}]({url})\nDuration: {duration} Minutes\n Requested by:</b> {from_user}",
f"__Added to queue at {pos}\n\n Title: [{name}]({url})\nDuration: {duration} Minutes\n Requested by:__ {from_user}",
file=thumb,
buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]],
)
elif VOICE_CHATS.get(chat.id) is None:
try:
await msg.edit(
"<i>Joining the voice chat...</i>", parse_mode="HTML"
)
await msg.edit("__Joining the voice chat...__")
await ins.join(chat.id)
VOICE_CHATS[chat.id] = ins
await sleep(3)
except Exception as e:
await msg.edit(
f"<i>Oops master, something wrong has happened. \n\nError:</i> <code>{e}</code>",
parse_mode="HTML",
f"__Oops master, something wrong has happened. \n\nError:__ `{e}`",
)
await VOICE_CHATS[chat.id].stop()
VOICE_CHATS.pop(chat.id)
Expand All @@ -115,7 +113,7 @@ async def play_song(event):
add_to_queue(chat, name, url, ref, "audio")
await sleep(3)
await msg.edit(
f"<b>Started Streaming\n\n Title: [{name}]({url})\n Duration: {duration} Minutes\n Requested by: {from_user}</b>",
f"**__Started Streaming\n\n Title__**: [{name}]({url})\n **__Duration:__** {duration} **__Minutes\n Requested by:__** {from_user}",
file=thumb,
buttons=[
[
Expand All @@ -130,7 +128,6 @@ async def play_song(event):
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML",
)
except Exception as e:
clear_queue(chat)
Expand All @@ -140,8 +137,8 @@ async def play_song(event):
return await sleep(3)

else:
await msg.edit("➕ <i>Downloading...</i>", parse_mode="HTML")
dl = await replied.download_media()
await msg.edit("➕ __Downloading...__")
dl = await replied.download_media(file=downloads_dir)
link = f"https://t.me/c/{chat.id}/{event.reply_to_msg_id}"
if replied.audio:
name = "Audio File"
Expand All @@ -150,7 +147,7 @@ async def play_song(event):
if chat.id in QUEUE:
pos = add_to_queue(chat, name, url, ref, "audio")
await msg.edit(
f"<b>Added to queue at {pos}\n\n Title: [{name}]({url})\n Requested by: {from_user}</b>",
f"**__Added to queue at__** {pos}\n\n **__Title:__** [{name}]({url})\n **__Requested by:__** {from_user}",
file=ngantri,
buttons=[
[
Expand All @@ -162,14 +159,12 @@ async def play_song(event):
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML",
)
else:
try:
await ins.start_audio(dl, repeat=False)
add_to_queue(chat, name, url, ref, "audio")
await msg.edit(
f"<b>Started Streaming</b>\n\n <b>Title: </b> [{name}]({link})\n <b>Requested by: </b> {from_user}",
f"**__Started Streaming\n\n Title: __** [{name}]({link})\n **__Requested by:**__ {from_user}",
file=fotoplay,
buttons=[
[
Expand All @@ -183,7 +178,6 @@ async def play_song(event):
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML",
)
except Exception as e:
clear_queue(chat)
Expand Down
Loading

0 comments on commit b5eaf9b

Please sign in to comment.