Пример #1
0
    async def fb_sfx(self, message, url):
        try:
            tag = TinyTag.get(url)
        except TinyTagException:
            return

        # Connection check
        if message.guild.voice_client is None:
            if message.author.voice:
                await message.author.voice.channel.connect()
                if message.guild.id not in self.players:
                    self.players[message.guild.id] = audioplayer.AudioPlayer(
                        self.client, message)
            else:
                return await message.send(
                    "You're not in a voice channel, silly. :eyes:")
        elif message.author.voice.channel != message.guild.voice_client.channel:
            return await message.send(
                "Come in here if you want me to play something. :eyes:")

        if tag.title is None:
            tag.title = url[url.rfind("/") + 1:]
        track = {"title": tag.title, "url": url, "track_type": "sfx"}

        if message.guild.id not in self.players:
            self.players[message.guild.id] = audioplayer.AudioPlayer(
                self.client, message)
        await self.players[message.guild.id].queue.put(track)
Пример #2
0
    async def sfx(self, message, *, url: str = None):
        track = {}
        if url is None:
            return await message.send(
                "You can browse the sfx folder with `browse sfx`, if you're looking for something specific."
            )
        elif os.path.exists(config.SFX_PATH + url + ".mp3"):
            track["url"] = config.SFX_PATH + url + ".mp3"
        elif os.path.exists(config.SFX_PATH + url + ".wav"):
            track["url"] = config.SFX_PATH + url + ".wav"
        else:
            return await message.send(
                "Couldn't find the sound effect you were looking for...")

        track["title"] = url
        track["track_type"] = "sfx"  # link / music / sfx

        # Connection check
        if message.guild.voice_client is None:
            if message.author.voice:
                await message.author.voice.channel.connect()
                if message.guild.id not in self.players:
                    self.players[message.guild.id] = audioplayer.AudioPlayer(
                        self.client, message)
            else:
                return await message.send(
                    "You're not in a voice channel, silly. :eyes:")
        elif message.author.voice.channel != message.guild.voice_client.channel:
            return await message.send(
                "Come in here if you want me to play something. :eyes:")

        if message.guild.id not in self.players:
            self.players[message.guild.id] = audioplayer.AudioPlayer(
                self.client, message)
        return await self.players[message.guild.id].queue.put(track)
Пример #3
0
    async def play(self, message, *, url: str = None):
        if message.guild.voice_client is None:
            if message.author.voice:
                await message.author.voice.channel.connect()
                if message.guild.id not in self.players:
                    self.players[message.guild.id] = audioplayer.AudioPlayer(
                        self.client, message)
            else:
                return await message.send(
                    "You're not in a voice channel, silly. :eyes:")
        elif message.author.voice.channel != message.guild.voice_client.channel:
            return await message.send(
                "Come in here if you want me to play something. :eyes:")

        if url is None:
            return await message.send(
                "You can browse the music folder with `browse music`, if you're looking for something specific."
            )
        elif url.startswith("https://www.youtube.com/") or url.startswith(
                "https://youtu.be/") or url.startswith(
                    "https://m.youtube.com/"):
            await self.prep_link_track(message, url)
        elif os.path.exists(config.MUSIC_PATH + url + ".mp3"):
            await self.prep_local_track(message, url + ".mp3")
        elif os.path.exists(config.MUSIC_PATH + url + ".wav"):
            await self.prep_local_track(message, url + ".wav")
        else:
            return await message.send(
                "I need a Youtube link or file path to play.")
Пример #4
0
 async def join(self, message):
     # Connection check
     if message.guild.voice_client is None:
         if message.author.voice:
             await message.author.voice.channel.connect()
             if message.guild.id not in self.players:
                 self.players[message.guild.id] = audioplayer.AudioPlayer(
                     self.client, message)
         else:
             return await message.send(
                 "You're not in a voice channel, silly. :eyes:")
     elif message.author.voice.channel != message.guild.voice_client.channel:
         return await message.guild.voice_client.move_to(
             message.author.voice.channel)
Пример #5
0
    async def track_loop(self):
        """ Centralize the queuing of tracks in this task """
        try:
            while self.running:
                track = await self.track_queue.get()
                message = track.get("message")

                if message.guild.id not in self.players:
                    self.players[message.guild.id] = audioplayer.AudioPlayer(
                        self.client, message)
                await self.players[message.guild.id].queue.put(track)
                if message.guild.voice_client.is_playing(
                ) or message.guild.voice_client.is_paused():
                    await message.channel.send(
                        "{} has been added to the queue.".format(
                            track.get("title")))

        except (asyncio.CancelledError, asyncio.TimeoutError):
            pass
Пример #6
0
    async def fb_play(self, message, url):
        """ Play command for the filebrowser """
        # Check if the requested track is within the cache folder or not because cached mp3s
        # should not have meta data. The track title is in the filename, though.
        track_title = ""
        if url[:url.rfind("/") + 1] == config.TEMP_PATH:
            track_title = url[url.rfind("/") + 1:len(url) - 16]

        else:
            # Try to extract meta data with tinytag, most normal mp3 files should have at least a title
            try:
                tag = TinyTag.get(url)
                if tag.title is None:
                    track_title = url[url.rfind("/") + 1:len(url) - 4]
                else:
                    track_title = tag.title
            except TinyTagException:
                return

        track = {
            "title": track_title,
            "url": url,
            "track_type": "music",
            "message": message
        }

        # Connection check
        if message.guild.voice_client is None:
            if message.author.voice:
                await message.author.voice.channel.connect()
                if message.guild.id not in self.players:
                    self.players[message.guild.id] = audioplayer.AudioPlayer(
                        self.client, message)
            else:
                return await message.send(
                    "You're not in a voice channel, silly. :eyes:")
        elif message.author.voice.channel != message.guild.voice_client.channel:
            return await message.send(
                "Come in here if you want me to play something. :eyes:")

        await self.track_queue.put(track)