Example #1
0
async def play(ctx, uri: str):
    """Plays the track of your choice."""
    if not bot.is_voice_connected(ctx.message.server):
        return

    after = lambda: bot.loop.create_task(bot.change_status(game=game.Game()))

    match = re.match(constants.RE_ATTACHMENT_URI, uri)
    if match is not None:
        if not bot.config['attachments']['enabled']:
            await bot.say('Support for attachments is currently disabled.')
            return

        discriminator = match.group(1)
        filename = match.group(2)
        path = os.path.join('attachments', discriminator, filename)
        if not os.path.exists(path):
            await bot.say('That attachment does not exist!')
            return

        await bot.play_attachment(path, after=after)
        return

    match = re.match(constants.RE_YOUTUBE_URL, uri)
    if match is not None:
        if not bot.config['youtube']['enabled']:
            await bot.say('Support for YouTube is currently disabled.')
            return

        await bot.play_youtube(uri, after=after)
        return

    match = re.match(constants.RE_SOUNDCLOUD_URL, uri)
    if match is not None:
        if not bot.config['soundcloud']['enabled']:
            await bot.say('Support for SoundCloud is currently disabled.')
            return

        await bot.play_soundcloud(uri, after=after)
        return

    await bot.say('Invalid URI.')
Example #2
0
 async def on_ready(self):
     print("Successfully connected!")
     await self.change_presence(game=game.Game(name="!dchelp"))
Example #3
0
 async def play_soundcloud(self, url, after=None):
     player = self.create_soundcloud_player(url, after=after)
     self.play(player)
     await self.change_status(game=game.Game(name=self.player.title))
Example #4
0
 async def play_youtube(self, url, after=None):
     player = await self.voice.create_ytdl_player(url, after=after)
     self.play(player)
     await self.change_status(game=game.Game(name=self.player.title))
Example #5
0
 async def play_attachment(self, path, after=None):
     player = self.voice.create_ffmpeg_player(path, after=after)
     self.play(player)
     basename = os.path.basename(path)
     await self.change_status(game=game.Game(name=basename))