Skip to content

Commit

Permalink
fix: bad read during stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Dysta committed Apr 22, 2024
1 parent 7dcc22b commit c3f6f10
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion jukebot/cogs/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ async def queue(self, inter: CommandInteraction):
inter : CommandInteraction
The interaction
"""
pass

@queue.sub_command()
@commands.cooldown(1, 3.0, BucketType.user)
Expand Down
1 change: 0 additions & 1 deletion jukebot/cogs/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import random
from typing import TYPE_CHECKING

import yaml
from disnake import CommandInteraction
from disnake.ext import commands
from disnake.ext.commands import BucketType
Expand Down
4 changes: 2 additions & 2 deletions jukebot/cogs/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import io
import os
from datetime import datetime
from typing import Optional, Set
from typing import Optional

from disnake import APISlashCommand, CommandInteraction, File
from disnake import CommandInteraction, File
from disnake.ext import commands
from loguru import logger

Expand Down
3 changes: 1 addition & 2 deletions jukebot/cogs/utility.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from datetime import datetime
from typing import Optional

from disnake import CommandInteraction, InviteTarget, Member
from disnake import CommandInteraction, InviteTarget
from disnake.ext import commands
from disnake.ext.commands import Bot, BucketType

Expand Down
28 changes: 16 additions & 12 deletions jukebot/components/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import os
from asyncio import Task
from enum import IntEnum
from enum import IntEnum, auto
from typing import Optional

from disnake import CommandInteraction, VoiceChannel, VoiceClient
Expand All @@ -21,12 +21,12 @@

class Player:
class State(IntEnum):
IDLE = 0
PLAYING = 1
PAUSED = 2
STOPPED = 3
SKIPPING = 4
DISCONNECTING = 5
IDLE = auto()
PLAYING = auto()
PAUSED = auto()
STOPPED = auto()
SKIPPING = auto()
DISCONNECTING = auto()

@property
def is_playing(self) -> bool:
Expand Down Expand Up @@ -96,7 +96,6 @@ async def play(self, song: Song, replay: bool = False):
song.requester = author

stream = AudioStream(song.stream_url)
stream.read()

if self._voice and self._voice.is_playing():
self._voice.stop()
Expand Down Expand Up @@ -134,13 +133,17 @@ def resume(self):
def _after(self, error):
if error:
logger.opt(lazy=True).error(error)
self.state = Player.State.IDLE
return

if self.state.is_leaving:
return

if self._loop.is_song_loop and not self.state.is_skipping:
func = self.play(self.song, replay=True)
coro.run_threadsafe(func, loop=self.bot.loop)
return

if self._loop.is_queue_loop:
with AddService(self.bot) as ad:
func = ad(interaction=self.interaction, query=self.song.web_url, silent=True)
Expand All @@ -153,8 +156,9 @@ def _after(self, error):
with PlayService(self.bot) as ps:
func = ps(interaction=self.interaction, query="")
coro.run_threadsafe(func, self.bot.loop)
else:
self.state = Player.State.IDLE
return

self.state = Player.State.IDLE

def _idle_callback(self) -> None:
if not self._idle_task.cancelled():
Expand Down Expand Up @@ -226,9 +230,9 @@ def state(self, new: State) -> None:
self._set_idle_task()

@property
def loop(self) -> "Player.Loop":
def loop(self) -> Player.Loop:
return self._loop

@loop.setter
def loop(self, lp: "Player.Loop") -> None:
def loop(self, lp: Player.Loop) -> None:
self._loop = lp
1 change: 0 additions & 1 deletion jukebot/components/requests/music_request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import asyncio
import pprint
from enum import Enum, auto

import yt_dlp
Expand Down
4 changes: 2 additions & 2 deletions jukebot/services/queue/add_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from jukebot.abstract_components import AbstractService
from jukebot.components.requests.music_request import MusicRequest
from jukebot.exceptions import QueryFailed
from jukebot.utils import embed, regex
from jukebot.utils import embed

if TYPE_CHECKING:
from jukebot.components import Player, Query, Result, ResultSet
from jukebot.components import Player, Result, ResultSet


class AddService(AbstractService):
Expand Down
2 changes: 1 addition & 1 deletion jukebot/utils/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import itertools
import random
from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING

import disnake
from disnake import Member
Expand Down
2 changes: 0 additions & 2 deletions tests/test_radios.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import asyncio
import unittest
from typing import Tuple

from jukebot.components.requests import MusicRequest
from jukebot.utils import converter
Expand Down

0 comments on commit c3f6f10

Please sign in to comment.