-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d5cb59
commit f2d15bb
Showing
6 changed files
with
41 additions
and
18 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,51 @@ | ||
import pickle | ||
from kreacher import client | ||
from pytgcalls import GroupCallFactory | ||
VOICE_CHATS = {} | ||
|
||
VOICE_CHATS_FILE = "voice_chats.pkl" | ||
|
||
|
||
def load_voice_chats(): | ||
try: | ||
with open(VOICE_CHATS_FILE, "rb") as file: | ||
return pickle.load(file) | ||
except FileNotFoundError: | ||
return {} | ||
|
||
|
||
def save_voice_chats(voice_chats): | ||
with open(VOICE_CHATS_FILE, "wb") as file: | ||
pickle.dump(voice_chats, file) | ||
|
||
|
||
async def create_voice_chat(chat_id): | ||
_factory = GroupCallFactory( | ||
client, GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON) | ||
voice_chat = _factory.get_group_call() | ||
current = VOICE_CHATS.get(chat_id) | ||
|
||
voice_chats = load_voice_chats() | ||
current = voice_chats.get(chat_id) | ||
|
||
if current is not None: | ||
raise Exception("I'am joined in the Voice Chat") | ||
else: | ||
VOICE_CHATS[chat_id] = voice_chat | ||
return True | ||
raise Exception("I'm joined in the Voice Chat") | ||
|
||
voice_chats[chat_id] = voice_chat | ||
save_voice_chats(voice_chats) | ||
|
||
|
||
async def get_voice_chat(chat_id): | ||
voice_chat = VOICE_CHATS.get(chat_id) | ||
if voice_chat is None: | ||
raise Exception("Streaming is not started") | ||
else: | ||
return voice_chat | ||
voice_chats = load_voice_chats() | ||
voice_chat = voice_chats.get(chat_id) | ||
|
||
return voice_chat | ||
|
||
|
||
async def stop_voice_chat(chat_id): | ||
voice_chat = VOICE_CHATS.get(chat_id) | ||
voice_chats = load_voice_chats() | ||
voice_chat = voice_chats.get(chat_id) | ||
|
||
if voice_chat is None: | ||
raise Exception("Streaming is not started") | ||
else: | ||
del VOICE_CHATS[chat_id] | ||
return True | ||
|
||
del voice_chats[chat_id] | ||
save_voice_chats(voice_chats) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.