-
Notifications
You must be signed in to change notification settings - Fork 0
/
admins.py
128 lines (109 loc) · 4.21 KB
/
admins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Calls Music 1 - Telegram bot for streaming audio in group calls
# Copyright (C) 2021 Roj Serbest
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from asyncio import QueueEmpty
from pyrogram import Client
from pyrogram import filters
from pyrogram.types import Message
from AlvinMusicRobot.config import que
from AlvinMusicRobot.function.admins import set
from AlvinMusicRobot.helpers.channelmusic import get_chat_id
from AlvinMusicRobot.helpers.decorators import authorized_users_only
from AlvinMusicRobot.helpers.decorators import errors
from AlvinMusicRobot.helpers.filters import command
from AlvinMusicRobot.helpers.filters import other_filters
from AlvinMusicRobot.services.callsmusic import callsmusic
from AlvinMusicRobot.services.queues import queues
@Client.on_message(filters.command("adminreset"))
async def update_admin(client, message: Message):
chat_id = get_chat_id(message.chat)
set(
chat_id,
[
member.user
for member in await message.chat.get_members(filter="administrators")
],
)
await message.reply_text("❇️ Admin cache refreshed!")
@Client.on_message(command("pause") & other_filters)
@errors
@authorized_users_only
async def pause(_, message: Message):
chat_id = get_chat_id(message.chat)
if (chat_id not in callsmusic.active_chats) or (
callsmusic.active_chats[chat_id] == "paused"
):
await message.reply_text("❗ tidak ada yang diputar!")
else:
callsmusic.pause(chat_id)
await message.reply_text("▶️ Paused!")
@Client.on_message(command("resume") & other_filters)
@errors
@authorized_users_only
async def resume(_, message: Message):
chat_id = get_chat_id(message.chat)
if (chat_id not in callsmusic.active_chats) or (
callsmusic.active_chats[chat_id] == "playing"
):
await message.reply_text("❗ tidak ada yang dijeda!")
else:
callsmusic.resume(chat_id)
await message.reply_text("⏸ Resumed!")
@Client.on_message(command("end") & other_filters)
@errors
@authorized_users_only
async def stop(_, message: Message):
chat_id = get_chat_id(message.chat)
if chat_id not in callsmusic.active_chats:
await message.reply_text("❗ tidak ada streaming!")
else:
try:
queues.clear(chat_id)
except QueueEmpty:
pass
await callsmusic.stop(chat_id)
await message.reply_text("❌ berhenti streaming!")
@Client.on_message(command("skip") & other_filters)
@errors
@authorized_users_only
async def skip(_, message: Message):
global que
chat_id = get_chat_id(message.chat)
if chat_id not in callsmusic.active_chats:
await message.reply_text("❗ tidak ada yang diputar untuk di skip!")
else:
queues.task_done(chat_id)
if queues.is_empty(chat_id):
await callsmusic.stop(chat_id)
else:
await callsmusic.set_stream(
chat_id,
queues.get(chat_id)["file_path"]
)
qeue = que.get(chat_id)
if qeue:
skip = qeue.pop(0)
if not qeue:
return
await message.reply_text(f"- Skipped **{skip[0]}**\n- diputar sekarang **{qeue[0][0]}**")
@Client.on_message(filters.command("admincache"))
@errors
async def admincache(client, message: Message):
set(
message.chat.id,
[
member.user
for member in await message.chat.get_members(filter="administrators")
],
)
await message.reply_text("❇️ Admin cache refreshed!")