Skip to content

Commit

Permalink
Added Autoend
Browse files Browse the repository at this point in the history
  • Loading branch information
KSKOP69 authored Oct 3, 2024
2 parents 2523fe6 + 24c800a commit 6692ee6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
56 changes: 31 additions & 25 deletions AlexaMusic/plugins/misc/autoleave.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import asyncio
from pyrogram.enums import ChatType
from datetime import datetime, timedelta

import config
from AlexaMusic import app
from AlexaMusic.core.call import Alexa
Expand All @@ -21,6 +23,7 @@
get_assistant,
)

autoend = {}

async def auto_leave():
if config.AUTO_LEAVING_ASSISTANT == str(True):
Expand Down Expand Up @@ -54,30 +57,33 @@ async def auto_leave():
asyncio.create_task(auto_leave())


# async def auto_end():
# while not await asyncio.sleep(5):
# if not await is_autoend():
# continue
# for chat_id in autoend:
# timer = autoend.get(chat_id)
# if not timer:
# continue
# if datetime.now() > timer:
# if not await is_active_chat(chat_id):
# autoend[chat_id] = {}
# continue
# autoend[chat_id] = {}
# try:
# await Alexa.stop_stream(chat_id)
# except:
# continue
# try:
# await app.send_message(
# chat_id,
# "ʙᴏᴛ ᴀᴜᴛᴏᴍᴀᴛɪᴄᴀʟʟʏ ᴄʟᴇᴀʀᴇᴅ ᴛʜᴇ ǫᴜᴇᴜᴇ ᴀɴᴅ ʟᴇғᴛ ᴠɪᴅᴇᴏᴄʜᴀᴛ ʙᴇᴄᴀᴜsᴇ ɴᴏ ᴏɴᴇ ᴡᴀs ʟɪsᴛᴇɴɪɴɢ sᴏɴɢs ᴏɴ ᴠɪᴅᴇᴏᴄʜᴀᴛ.",
# )
# except:
# continue
async def auto_end():
while True:
await asyncio.sleep(30)
for chat_id, timer in list(autoend.items()):
if datetime.now() > timer:
if not await is_active_chat(chat_id):
del autoend[chat_id]
continue
userbot = await get_assistant(chat_id)
members = []
async for member in userbot.get_call_members(chat_id):
if member is None:
continue
members.append(member)
if len(members) <= 1:
try:
await Alexa.stop_stream(chat_id)
except Exception:
pass
try:
await app.send_message(
chat_id,
"ʙᴏᴛ ᴀᴜᴛᴏᴍᴀᴛɪᴄᴀʟʟʏ ᴄʟᴇᴀʀᴇᴅ ᴛʜᴇ ǫᴜᴇᴜᴇ ᴀɴᴅ ʟᴇғᴛ ᴠɪᴅᴇᴏᴄʜᴀᴛ ʙᴇᴄᴀᴜsᴇ ɴᴏ ᴏɴᴇ ᴡᴀs ʟɪsᴛᴇɴɪɴɢ sᴏɴɢs ᴏɴ ᴠɪᴅᴇᴏᴄʜᴀᴛ.",
)
except Exception:
pass
del autoend[chat_id]


# asyncio.create_task(auto_end())
asyncio.create_task(auto_end())
21 changes: 20 additions & 1 deletion AlexaMusic/plugins/misc/seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
import asyncio

from pyrogram.types import InlineKeyboardMarkup
from datetime import datetime, timedelta

from strings import get_string
from AlexaMusic.misc import db
from AlexaMusic.utils.database import get_active_chats, get_lang, is_music_playing
from AlexaMusic.utils.database import (
get_active_chats,
get_lang,
is_music_playing,
get_assistant,
)
from AlexaMusic.utils.formatters import seconds_to_min
from AlexaMusic.utils.inline import stream_markup_timer, telegram_markup_timer

from ..admins.callback import wrong
from .autoleave import autoend

checker = {}

Expand Down Expand Up @@ -75,6 +82,18 @@ async def markup_timer():
_ = get_string(language)
except:
_ = get_string("en")
userbot = await get_assistant(chat_id)
if chat_id not in autoend:
try:
members = []
async for member in userbot.get_call_members(chat_id):
if member is None:
continue
members.append(member)
if len(members) <= 1:
autoend[chat_id] = datetime.now() + timedelta(seconds=60)
except Exception:
pass # Passing this for don't affect the below button edition function
try:
buttons = (
stream_markup_timer(
Expand Down

0 comments on commit 6692ee6

Please sign in to comment.