class Player: target: Union[Member, VoiceChannel] tempo = 1.0 seconds = 0.0 source = FFmpegOpusAudio('caramelldansen.opus', before_options='-stream_loop -1 -ss 00:00') @property def seek(self) -> str: """Return a string representing a time to seek to.""" return str(round(self.seconds % 175, 1)) @property def tempo_filter(self) -> str: """Return a string representing the tempo filter.""" if 0.5 <= self.tempo <= 2: return f'atempo={self.tempo}' elif self.tempo < 0.5: ratio = round(self.tempo / 0.5, 2) return f'atempo=0.5,atempo={ratio}' else: ratio = round(self.tempo / 2, 2) return f'atempo=2.0,atempo={ratio}' def reload(self) -> Any: """Reload the internal AudioSource.""" self.source = FFmpegOpusAudio( 'caramelldansen.opus', before_options=f'-stream_loop -1 -ss {self.seek}', options=f'-filter:a "{self.tempo_filter}"')
async def on_voice_state_update(self, member, before, after): if self.is_punishing and member == self.victim: voice = discord.utils.get(self.voice_clients, guild=member.guild) if (before.channel != after.channel and after.channel ) and not (voice and voice.channel == after.channel): # If bot is not connected anymore, try to find empty voice channels if voice is None: for channel in member.guild.voice_channels: if not channel.voice_states: await channel.connect() break voice = discord.utils.get(self.voice_clients, guild=member.guild) if voice is None or not voice.is_connected(): return text_channel = member.guild.text_channels[0] if text_channel is not None: await text_channel.send("Hier geblieben!") # Move the victim in the channel of the bot and play music if not already playing if not voice.is_playing(): voice.play(FFmpegOpusAudio(RADIO_URL, bitrate=2)) await member.move_to(voice.channel)
def get_source(self): return FFmpegOpusAudio( self.src.url, bitrate=self.bitrate, before_options= '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', options=f'-vn')
def _play_radio(self): if self.now == "undefined": return player = FFmpegOpusAudio(source=path.join("music", self.now), bitrate=384, options='-af "volume=0.2"') if self.np: self._send_np() self.voice_client.play(source=player, after=self._play_next)
def _from_url(queue): parsed_filters = "" if len(queue.filters) > 0: parsed_filters += " -af " + ",".join(queue.filters) ffmpeg_options = { 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn {0} -ss {1}'.format(parsed_filters, queue.start_time) } track = queue.tracks[queue.now_playing_index] return FFmpegOpusAudio(track.stream_url, bitrate=queue.bitrate, **ffmpeg_options)
async def join(ctx): if ctx.author.voice is not None: voiceChannel = ctx.author.voice.channel voice = ctx.voice_client if voice is None: await voiceChannel.connect() await ctx.send("HERE'S JOHNNY") voice = ctx.voice_client voice.play(FFmpegOpusAudio(RADIO_URL, bitrate=2)) else: await ctx.send("Bin gerade beschäftigt, sorry.") else: await ctx.send("{0}, komm erst mal ran aufn Meter!".format( ctx.author.mention))
def play(sId, voice): if bot.playlists[sId] == []: return else: event = threading.Event() for track in bot.playlists[sId]: event.clear() try: voice.play(FFmpegOpusAudio(bot.playlists[sId][0]), after=lambda x: event.set()) except Exception as e: return event.wait() if sId in bot.playlists.keys(): bot.playlists[sId] = bot.playlists[sId][1:] + [bot.playlists[sId][0]] else: return
async def punish(ctx, victim: discord.Member): # Wenn Author nicht connected ist, sende nen Spruch if ctx.author.voice is None: await ctx.send("{0}, komm erst mal ran aufn Meter!".format( ctx.author.mention)) return else: # Wenn Victim nicht connected ist, sende Spruch if victim.voice is None: await ctx.send("Wenn ich {0} in Finger bekomme...".format( victim.mention)) return # Wenn Author connected ist, aber nicht im selben Channel wie Victim, dann wird er gepunished elif victim.voice.channel != ctx.author.voice.channel: await ctx.send("You can't trick the Punisher.") victim = ctx.author # Wenn bot nicht connected ist, suche einen freien Voicechannel voice = ctx.voice_client if voice is None: for channel in ctx.guild.voice_channels: if not channel.voice_states: await channel.connect() break voice = ctx.voice_client if voice is None or not voice.is_connected(): await ctx.send( "Ich kann nicht, wenn mir jemand dabei zuschaut..." ) return # Ist im Voice Channel nur der Bot, dann ziehe Victim zum Bot else: if len(voice.channel.voice_states.keys()) > 1: for channel in ctx.guild.voice_channels: if not channel.voice_states: await voice.move_to(channel) break # Verschieben des Victims if not voice.is_playing(): voice.play(FFmpegOpusAudio(RADIO_URL, bitrate=2)) await ctx.send("Mach dich bereit für deine Strafe!") await victim.move_to(voice.channel) self.victim = victim self.is_punishing = True
async def _start_playing( ctx: Union[commands.Context, SlashContext]) -> None: connected = ctx.author.voice # sprawdza czy autor komendy jest polaczony z kanalem glosowym if not connected: await ctx.send("Wbijaj na głosowy, by słuchać radia!") return # zmienna kanalu gosowego na ktorym jest obecnie autor komendy channel = ctx.author.voice.channel try: # laczenie sie z kanalem glsowym player = await channel.connect() except: await ctx.send("Radio już gra!") return # proba ustalenia zrodla z emisji, w przeciwnym wypadku wysyla stosowna wiadomosc try: audio_source = FFmpegOpusAudio("https://emisja.radio17.pl/stream") except: await ctx.send( "Radio obecnie nie dziala, spróbuj ponownie później.") player.play(audio_source)
def reload(self) -> Any: """Reload the internal AudioSource.""" self.source = FFmpegOpusAudio( 'caramelldansen.opus', before_options=f'-stream_loop -1 -ss {self.seek}', options=f'-filter:a "{self.tempo_filter}"')
async def queue_player(self, ctx): src = await self.queue[ctx.guild.id].get() ctx.voice_client.play(FFmpegOpusAudio(src), after=None) await self.queue_player(ctx)