Skip to content

Commit

Permalink
Change to .pkl
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Aug 7, 2023
1 parent c57e84c commit fbfbac1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 53 deletions.
10 changes: 0 additions & 10 deletions .codesandbox/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions .codesandbox/tasks.json

This file was deleted.

Binary file added .github/images/gitpod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion bot/dbs/actives.pkl
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
[]
1 change: 0 additions & 1 deletion bot/dbs/vcs.pkl
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
[]
42 changes: 28 additions & 14 deletions bot/helpers/queues.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import os
import pickle

active = []
dir = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(dir, "../dbs/queues.pkl")
actives = os.path.join(dir, "../dbs/actives.pkl")


async def get_active_chats() -> list:
return active
with open(actives, "r") as a:
ACTIVE = pickle.load(a)
return ACTIVE


def add_to_queue(chat, name, url, ref, type):
with open(queues, "r+") as f:
QUEUE = pickle.load(f)
with open(queues, "r") as q:
QUEUE = pickle.load(q)
with open(actives, "r") as a:
ACTIVE = pickle.load(a)
try:
if chat.id in QUEUE:
QUEUE[chat.id].append([name, url, ref, type])
pickle.dump(QUEUE[chat.id], f)
with open(queues, "w") as q:
pickle.dump(QUEUE, q)
return int(len(QUEUE[chat.id]) - 1)
if chat.id not in active:
active.append(chat.id)
with open(actives, "w") as a:
pickle.dump(ACTIVE, a)
QUEUE[chat.id] = [[name, url, ref, type]]
with open(queues, "w") as q:
pickle.dump(QUEUE, q)
except Exception as e:
raise e


def get_queue(chat):
with open(queues, "r") as f:
with open(queues, "r") as q:
QUEUE = pickle.load(f)
try:
if chat.id in QUEUE:
Expand All @@ -38,28 +46,34 @@ def get_queue(chat):


def pop_an_item(chat):
with open(queues, "r+") as f:
QUEUE = pickle.load(f)
with open(queues, "r") as q:
QUEUE = pickle.load(q)
try:
if chat.id not in QUEUE:
return 0
QUEUE[chat.id].pop(0)
pickle.dump(QUEUE)
with open(queues, "w") as q:
pickle.dump(QUEUE, q)
return 1
except Exception as e:
raise e


def clear_queue(chat):
with open(queues, "r+") as f:
QUEUE = pickle.load(f)
with open(queues, "r") as q:
QUEUE = pickle.load(q)
with open(actives, "r") as a:
ACTIVE = pickle.load(a)
try:
if chat.id not in QUEUE:
return 0
QUEUE.pop(chat.id)
pickle.dump(QUEUE)
if chat.id in active:
active.remove(chat.id)
with open(queues, "w") as q:
pickle.dump(QUEUE, q)
if chat.id in ACTIVE:
ACTIVE.remove(chat.id)
with open(actives, "r") as a:
pickle.dump(ACTIVE, a)
return 1
except Exception as e:
raise e
File renamed without changes.
15 changes: 11 additions & 4 deletions bot/plugins/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import pickle
from asyncio import sleep
from bot import config, kreacher
from bot.dicts.dicts import QUEUE, VOICE_CHATS
from bot.dicts.dicts import VOICE_CHATS
from telethon import events, Button
from bot.helpers.queues_handler import next_item, skip_current

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

dir = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(dir, "../dbs/queues.pkl")

@kreacher.on(events.callbackquery.CallbackQuery(data="cls"))
async def _(event):
await event.delete()


@kreacher.on(
events.callbackquery.CallbackQuery(data="pause_or_resume_callback")
)
@kreacher.on(events.callbackquery.CallbackQuery(data="pause_or_resume_callback"))
async def _(event):
chat = await event.get_chat()
if VOICE_CHATS[chat.id].is_video_paused:
Expand Down Expand Up @@ -58,6 +59,8 @@ async def _(event):

@kreacher.on(events.callbackquery.CallbackQuery(data="next_callback"))
async def _(event):
with open(queues, "r") as q:
QUEUE = pickle.load(q)
chat = await event.get_chat()
if len(event.text.split()) < 2:
op = await skip_current(chat)
Expand Down Expand Up @@ -88,8 +91,12 @@ async def _(event):

@kreacher.on(events.callbackquery.CallbackQuery(data="end_callback"))
async def _(event):
with open(queues, "r") as q:
QUEUE = pickle.load(q)
chat = await event.get_chat()
QUEUE.pop(chat.id)
with open(queues, "w") as q:
pickle.dump(QUEUE,q)
await VOICE_CHATS[chat.id].stop_media()
await VOICE_CHATS[chat.id].stop()
VOICE_CHATS.pop(chat.id)
Expand Down

0 comments on commit fbfbac1

Please sign in to comment.