-
Notifications
You must be signed in to change notification settings - Fork 22
/
voice_chat.py
168 lines (136 loc) · 5.56 KB
/
voice_chat.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# TODO
# WARNING! COMMENTED SINCE LOADING THIS MODULE
# WILL CAUSE TO MANY ERRORS AND MAY LEAD TO
# MEMORY LEAKING AND ERRORS ON HOST
# THIS MODULE ISN'T COMPATIBLE WITH DRAGON-4.0
# AND NEEDS TO BE REWRITE
# SOME LINES FROM THIS FILES - ARE MY ATTEMPT TO REWRITE IT
# pytgcalls = import_library("pytgcalls", "py-tgcalls")
# from pytgcalls.types import AudioPiped
# @Client.on_message(filters.command("play", prefix) & filters.me)
# @with_reply
# async def start_playout(client, message: Message):
# chat_id = message.chat.id
# audio = await message.reply_to_message.download("input.raw")
# if audio is None:
# await message.edit("Error while downloading.")
# return
# app = pytgcalls.PyTgCalls(client)
# await app.start()
# try:
# await app.join_group_call(
# chat_id,
# AudioPiped(
# audio
# ))
# except:
# await message.edit("Something went wrong.")
# await message.reply("fuck")
# import os
# from contextlib import suppress
# import ffmpeg
# from pyrogram import Client, filters
# from pyrogram.types import Message
# from utils.misc import modules_help, prefix
# from utils.scripts import import_library, with_reply, restart
# pytgcalls = import_library("pytgcalls")
# from pytgcalls import GroupCallFactory
# group_call = None
# def init_client(func):
# async def wrapper(client, message):
# global group_call
# if not group_call:
# group_call = GroupCallFactory(client).get_file_group_call()
# group_call.enable_logs_to_console = False
# return await func(client, message)
# return wrapper
# @Client.on_message(filters.command("play", prefix) & filters.me)
# @with_reply
# async def start_playout(_, message: Message):
# if not group_call:
# await message.reply(
# f"<b>You are not joined [type <code>{prefix}join</code>]</b>"
# )
# return
# if not message.reply_to_message.audio:
# await message.edit("<b>Reply to a message containing audio</b>")
# return
# input_filename = "input.raw"
# await message.edit("<b>Downloading...</b>")
# audio_original = await message.reply_to_message.download()
# await message.edit("<b>Converting..</b>")
# ffmpeg.input(audio_original).output(
# input_filename, format="s16le", acodec="pcm_s16le", ac=2, ar="48k"
# ).overwrite_output().run()
# os.remove(audio_original)
# await message.edit(f"<b>Playing {message.reply_to_message.audio.title}</b>...")
# group_call.input_filename = input_filename
# @Client.on_message(filters.command("volume", prefix) & filters.me)
# @init_client
# async def volume(_, message):
# if len(message.command) < 2:
# await message.edit("<b>You forgot to pass volume [1-200]</b>")
# await group_call.set_my_volume(message.command[1])
# await message.edit(
# f"<b>Your volume is set to</b><code> {message.command[1]}</code>"
# )
# @Client.on_message(filters.command("join", prefix) & filters.me)
# @init_client
# async def start(_, message: Message):
# chat_id = message.command[1] if len(message.command) > 1 else message.chat.id
# with suppress(ValueError):
# chat_id = int(chat_id)
# try:
# await group_call.start(chat_id)
# await message.edit("<b>Joining successfully!</b>")
# except Exception as e:
# await message.edit(f"<b>An unexpected error has occurred: <code>{e}</code></b>")
# @Client.on_message(filters.command("leave_voice", prefix) & filters.me)
# @init_client
# async def stop(_, message: Message):
# try:
# await group_call.stop()
# await message.edit("<b>Leaving successfully!</b>")
# except Exception as e:
# await message.edit(
# f"<b>Аn unexpected error occurred [<code>{e}</code>]\n"
# "The bot will try to exit the voice chat by restarting itself,"
# "the bot will be unavailable for the next 4 seconds</b>"
# )
# restart()
# @Client.on_message(filters.command("stop", prefix) & filters.me)
# @init_client
# async def stop_playout(_, message: Message):
# group_call.stop_playout()
# await message.edit("<b>Stoping successfully!</b>")
# @Client.on_message(filters.command("vmute", prefix) & filters.me)
# @init_client
# async def mute(_, message: Message):
# group_call.set_is_mute(True)
# await message.edit("<b>Sound off!</b>")
# @Client.on_message(filters.command("vunmute", prefix) & filters.me)
# @init_client
# async def unmute(_, message: Message):
# group_call.set_is_mute(False)
# await message.edit("<b>Sound on!</b>")
# @Client.on_message(filters.command("pause", prefix) & filters.me)
# @init_client
# async def pause(_, message: Message):
# group_call.pause_playout()
# await message.edit("<b>Paused!</b>")
# @Client.on_message(filters.command("resume", prefix) & filters.me)
# @init_client
# async def resume(_, message: Message):
# group_call.resume_playout()
# await message.edit("<b>Resumed!</b>")
# modules_help["voice_chat"] = {
# "play [reply]*": "Play audio in replied message",
# "volume [1 – 200]": "Set the volume level from 1 to 200",
# "join [chat_id]": "Join the voice chat",
# "leave_voice": "Leave voice chat",
# "stop": "Stop playback",
# "vmute": "Mute the userbot",
# "vunmute": "Unmute the userbot",
# "pause": "Pause",
# "resume": "Resume",
# }