Example #1
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.players.create(ctx.guild.id,
                                                  endpoint=str(
                                                      ctx.guild.region))
        # Create returns a player if one exists, otherwise creates.

        should_connect = ctx.command.name in (
            'play')  # Add commands that require joining voice to work.

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError(':x: | 먼저 음성채널 부터 들가고 말하시져 ;;;')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError(
                    ':x: | 채널에 연결되어있지 않습니다. 저를 빼다니 속상하네요..ㅠㅠ')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    ':x: | 권한이 부족하거나 사람이 너무 많네요 ;;')

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    ':x: | 어.. 그니까 저는 다른 채널에 빼놓고 지들끼리만 파티하는 거죠..?')
Example #2
0
 async def ensure_voice(self, ctx):
     player = self.bot.lavalink.players.create(ctx.guild.id,
                                               endpoint=str(
                                                   ctx.guild.region))
     should_connect = ctx.command.name in ('play', 'join', 'why', 'tts',
                                           'join', 'gachibass')
     if not ctx.author.voice or not ctx.author.voice.channel:
         raise commands.CommandInvokeError(
             'Сначала подключитесь к голосовому каналу')
     if not player.is_connected:
         if not should_connect:
             raise commands.CommandInvokeError('Я не подключен к каналу')
         permissions = ctx.author.voice.channel.permissions_for(ctx.me)
         if not permissions.connect or not permissions.speak:
             raise commands.CommandInvokeError(
                 'I need the `CONNECT` and `SPEAK` permissions.')
         player.store('channel', ctx.channel.id)
         await self.connect_to(ctx.guild.id,
                               str(ctx.author.voice.channel.id))
     else:
         if int(player.channel_id
                ) == ctx.author.voice.channel.id and should_connect:
             return
         if should_connect:
             return await self.connect_to(ctx.guild.id,
                                          str(ctx.author.voice.channel.id))
         if int(player.channel_id) != ctx.author.voice.channel.id:
             raise commands.CommandInvokeError(
                 'Мы в разных голосовых каналах')
Example #3
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.players.create(ctx.guild.id,
                                                  endpoint=str(
                                                      ctx.guild.region))
        # Create returns a player if one exists, otherwise creates.

        should_connect = ctx.command.name in (
            'play')  # Add commands that require joining voice to work.

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError('Join a voicechannel first.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Not connected.')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                raise commands.CommandInvokeError(
                    'I need the `CONNECT` and `SPEAK` permissions.')

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    'You need to be in my voicechannel.')
Example #4
0
    async def ensure_voice(self, ctx):
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))
        should_connect = ctx.command.name in ('play', 'melonplay',
                                              'billboardplay', 'connect',
                                              'find', 'list')

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError(
                get_lan(ctx.author.id, "music_come_in_voice_channel"))
        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError(
                    get_lan(ctx.author.id,
                            "music_not_connected_voice_channel"))
            permissions = ctx.author.voice.channel.permissions_for(ctx.me)
            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    get_lan(ctx.author.id, "music_no_permission"))
            player.store('channel', ctx.channel.id)
            player.fetch('channel')
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    get_lan(ctx.author.id, "music_come_in_my_voice_channel"))
Example #5
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))
        should_connect = ctx.command.name in ('play', 'ytsearch', 'connect')

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError('You are not in a voice channel')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError(
                    'Not connected to any voice channel.')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                raise commands.CommandInvokeError(
                    'I need the `CONNECT` and `SPEAK` permissions.')

            player.store('channel', ctx.channel.id)
            await ctx.guild.change_voice_state(
                channel=ctx.author.voice.channel, self_deaf=True)
            em = discord.Embed(
                description=f"Joined {ctx.author.voice.channel.mention}",
                color=discord.Color.blurple())
            await ctx.send(embed=em)
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    'You are not in the same voice channel.')
Example #6
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))

        should_connect = ctx.command.name in ('play', )

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError('Join a voicechannel first.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Not connected.')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    'I need the `CONNECT` and `SPEAK` permissions.')

            player.store('channel', ctx.channel.id)
            await ctx.author.voice.channel.connect(cls=LavalinkVoiceClient)
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    'You need to be in my voicechannel.')
Example #7
0
        async def ensure_voice_inner(self, ctx, *command_args, **kwargs):
            """ This check ensures that the bot and command author are in the same voicechannel. """

            player = self.bot.lavalink.player_manager.get(ctx.guild.id)
            if not ctx.author.voice or not ctx.author.voice.channel:
                raise commands.CommandInvokeError('Join a voicechannel first.')

            if not player.is_connected:
                if not should_connect:
                    raise commands.CommandInvokeError('Not connected.')

                user_voice_channel = ctx.author.voice.channel
                permissions = user_voice_channel.permissions_for(ctx.me)

                if not permissions.connect or not permissions.speak:  # Check user limit too?
                    raise commands.CommandInvokeError(
                        'I need the `CONNECT` and `SPEAK` permissions.')

                if (len(user_voice_channel.members)
                        == user_voice_channel.user_limit
                    ) and not permissions.administrator:
                    raise commands.CommandInvokeError(
                        'The channel is currently full')

                # Check against music channel restrictions in bot settings
                if voice_channels := self.bot.settings.get(
                        ctx.guild, 'channels.music', []):
                    if user_voice_channel.id not in voice_channels:
                        raise WrongVoiceChannelError(
                            'You need to be in the right voice channel',
                            channels=voice_channels)

                player.store('channel', ctx.channel.id)
                await self.connect_to(ctx.guild.id,
                                      str(ctx.author.voice.channel.id))
Example #8
0
    async def ensure_voice(self, ctx):
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))

        should_connect = ctx.command.name in ('play')

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError(
                '<:no:830635025187209216> Join a Voice Channel first')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError(
                    '<:no:830635025187209216> Not connected')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    '<:no:830635025187209216> I need the `CONNECT` and `SPEAK` permissions'
                )

            player.store('channel', ctx.channel.id)
            await ctx.guild.change_voice_state(channel=ctx.author.voice.channel
                                               )
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    '<:no:830635025187209216> You need to be in my Voice Channel'
                )
Example #9
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))
        should_connect = ctx.command.name in ("play", "find")

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError("Join a voicechannel first.")

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError("Not connected.")

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    "I need the `CONNECT` and `SPEAK` permissions.")

            player.store("channel", ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    "You need to be in my voicechannel.")
Example #10
0
    async def ensure_voice(self, ctx):

        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))

        should_connect = ctx.command.name in ('play', )

        if not ctx.author.voice or not ctx.author.voice.channel:

            raise commands.CommandInvokeError('Join a voicechannel first.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Not connected.')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                raise commands.CommandInvokeError(
                    'I need the `CONNECT` and `SPEAK` permissions.')

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    'You need to be in my voicechannel.')
Example #11
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id, endpoint=str(ctx.guild.region))
        # Create returns a player if one exists, otherwise creates.
        # This line is important because it ensures that a player always exists for a guild.

        # Most people might consider this a waste of resources for guilds that aren't playing, but this is
        # the easiest and simplest way of ensuring players are created.

        # These are commands that require the bot to join a voicechannel (i.e. initiating playback).
        # Commands such as volume/skip etc don't require the bot to be in a voicechannel so don't need listing here.
        should_connect = ctx.command.name in ('play',)

        if not ctx.author.voice or not ctx.author.voice.channel:
            # Our cog_command_error handler catches this and sends it to the voicechannel.
            # Exceptions allow us to "short-circuit" command invocation via checks so the
            # execution state of the command goes no further.
            raise commands.CommandInvokeError('Join a voicechannel first.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Not connected.')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                raise commands.CommandInvokeError('I need the `CONNECT` and `SPEAK` permissions.')

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id, str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError('You need to be in my voicechannel.')
Example #12
0
    def __init__(self,
                 dice_sides: int,
                 kh: int = None,
                 kl: int = None,
                 exp: int = None):
        self.sides = dice_sides
        self.kh = kh
        self.kl = kl
        self.e = exp

        if kh and kl:
            raise commands.CommandInvokeError(
                "<:wellfuck:704784002166554776> KH and KL cannot be specified on the same throw."
            )

        if dice_sides == 1 and exp == 1:
            raise commands.CommandInvokeError(
                "<:wellfuck:704784002166554776> **Hold on there, you can't just go around "
                "throwing infinite dice like you own the place!**")

        if self.kh is None:
            self.kh = -1
        if self.kl is None:
            self.kl = -1
        if self.e is None:
            self.e = -1

        if self.kh < 0 and self.kh != -1 or self.kl < 0 and self.kl != -1:
            raise commands.CommandInvokeError(
                "<:wellfuck:704784002166554776> **I'm sorry but you can't keep a negative "
                "number of dice, that just doesn't work does it.**")
Example #13
0
async def ensure_voice(bot, ctx):
    """ This check ensures that the bot and command author are in the same voicechannel. """
    player = bot.lavalink.player_manager.create(ctx.guild.id,
                                                endpoint=str(ctx.guild.region))
    # Create returns a player if one exists, otherwise creates.

    should_connect = ctx.command.name in [
        "play", "search"
    ]  # Add commands that require joining voice to work.

    if not ctx.author.voice or not ctx.author.voice.channel:
        raise commands.CommandInvokeError("Join a voicechannel first.")

    if not player.is_connected:
        if not should_connect:
            raise commands.CommandInvokeError("Not connected.")

        permissions = ctx.author.voice.channel.permissions_for(ctx.me)

        if not permissions.connect or not permissions.speak:  # Check user limit too?
            raise commands.CommandInvokeError(
                "I need the `CONNECT` and `SPEAK` permissions.")

        player.store("channel", ctx.channel.id)
        player.store("autoplay", AutoPlay())
        player.store("autoplay_enabled", True)
        await connect(bot, ctx.guild.id, ctx.author.voice.channel.id)
    else:
        if int(player.channel_id) != ctx.author.voice.channel.id:
            raise commands.CommandInvokeError(
                "You need to be in my voicechannel.")
Example #14
0
    async def ensure_voice(self, ctx: Context):
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))
        should_connect = ctx.command.name in ("play", )

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError(
                "보이스채널에 연결되어있지 않습니다! 보이스채널에 들어가신후 저를 불러주세요!")

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError(
                    "보이스채널에 연결되어있지 않습니다! 보이스채널에 들어가신후 저를 불러주세요!")

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    f"{ctx.bot.mention} 에게 보이스 연결, 말하기 권한이 있어야해요!")

            player.store("channel", ctx.channel.id)
            await ctx.guild.change_voice_state(channel=ctx.author.voice.channel
                                               )
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    f"{str(ctx.author)} 님은 제가 있는 보이스채널에 들어와주세요!")
Example #15
0
    async def ensure_voice(self, ctx):
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))
        should_connect = ctx.command.name in ('play', 'melonplay', 'connect',
                                              'find')

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError('먼저 음성 채널에 들어와주세요.')
        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError(
                    ':warning: | 음성 채널에 연결되어 있지 않아요!')
            permissions = ctx.author.voice.channel.permissions_for(ctx.me)
            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    ':warning: | 권한이 없어요! (Connect, Speak 권한을 주세요!)')
            player.store('channel', ctx.channel.id)
            player.fetch('channel')
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    ':warning: | 다른 음성 채널에 있어요! 제가 있는 음성 채널로 와주세요.')
Example #16
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))

        should_connect = ctx.command.name in ('play', 'playfromlist')

        if not ctx.author.voice or not ctx.author.voice.channel:
            # Our cog_command_error handler catches this and sends it to the voicechannel.
            # Exceptions allow us to "short-circuit" command invocation via checks so the
            # execution state of the command goes no further.
            raise commands.CommandInvokeError('Join a voicechannel first.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Not connected.')

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:
                raise commands.CommandInvokeError(
                    'I need the `CONNECT` and `SPEAK` permissions.')

            player.store('channel', ctx.channel.id)
            await ctx.guild.change_voice_state(channel=ctx.author.voice.channel
                                               )
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    'You need to be in my voicechannel.')
Example #17
0
        async def ensure_play_inner(self, ctx, *command_args, **kwargs):

            if player := self.bot.lavalink.player_manager.get(ctx.guild.id):

                if not player.is_playing:
                    raise commands.CommandInvokeError('Not playing')

                if require_user_listening and (ctx.author
                                               not in player.listeners):
                    raise commands.CommandInvokeError('Not listening')
Example #18
0
    async def ensure_voice(self, ctx, do_connect: Optional[bool] = None):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.players.create(
            ctx.guild.id, endpoint=ctx.guild.region.value)
        # Create returns a player if one exists, otherwise creates.

        should_connect = ctx.command.callback.__name__ in (
            '_play', '_find', '_search'
        )  # Add commands that require joining voice to work.
        without_connect = ctx.command.callback.__name__ in (
            '_queue', '_history', '_now', '_lyrics'
        )  # Add commands that don't require the you being in voice.

        if without_connect:
            return

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError('Join a voicechannel first.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Not connected.')

            voice_channel = ctx.author.voice.channel

            permissions = voice_channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                raise commands.CommandInvokeError(
                    'I need the `CONNECT` and `SPEAK` permissions.')

            voice_channels = self.bot.settings.get(ctx.guild, 'channels.music',
                                                   [])

            if voice_channels:
                if voice_channel.id not in voice_channels:
                    response = ctx.localizer.format_str(
                        '{settings_check.voicechannel}')
                    for channel_id in voice_channels:
                        channel = ctx.guild.get_channel(channel_id)
                        if channel is not None:
                            response += f'{channel.name}, '
                    await ctx.send(response[:-2])
                    raise commands.CommandInvokeError(
                        'You need to be in the right voice channel')

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))

        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError(
                    'You need to be in my voicechannel.')
Example #19
0
 async def giphy_results(self, gif):
     giphy_url = (f'http://api.giphy.com/v1/gifs/search' +
                  f'?api_key={self.bot.config.giphy}' + f'&q={quote(gif)}' +
                  f'&lang=en')
     async with self.bot.session.get(giphy_url) as r:
         if r.status != 200:
             raise commands.CommandInvokeError(self.bot.BAD_RESPONSE)
         gifs = await r.json()
     try:
         gif = random.choice(gifs['data'])['images']['original']['url']
     except IndexError:
         raise commands.CommandInvokeError(self.bot.NO_RESULTS)
     return gif
Example #20
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))

        should_connect = ctx.command.name in (
            'play', )  # Add commands that require joining voice to work.
        should_not_connect = ctx.command.name in ('lyrics', )

        if should_not_connect:
            return

        if not ctx.author.voice or not ctx.author.voice.channel:
            embed = discord.Embed(
                color=self.bot.embed_color,
                title="→ Voice Channel Error!",
                description="• Please make sure to join a voice channel first!"
            )
            raise commands.CommandInvokeError(await ctx.send(embed=embed))

        if not player.is_connected:
            if not should_connect:
                embed = discord.Embed(
                    color=self.bot.embed_color,
                    title="→ Voice Channel Error!",
                    description="• I am not connected to a voice channel")
                raise commands.CommandInvokeError(await ctx.send(embed=embed))

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                embed = discord.Embed(
                    color=self.bot.embed_color,
                    title="→ Permission Error!",
                    description=
                    "• Please give me connect permissions, or speaking permissions!"
                )
                await ctx.send(embed=embed)

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                embed = discord.Embed(
                    color=self.bot.embed_color,
                    title="→ Voice Channel Error!",
                    description=
                    "• Please make sure you are in my voice channel!")
                raise commands.CommandInvokeError(await ctx.send(embed=embed))
Example #21
0
    async def ensure_voice(self, ctx):
        """ This check ensures that the bot and command author are in the same voicechannel. """
        player = self.bot.lavalink.player_manager.create(ctx.guild.id,
                                                         endpoint=str(
                                                             ctx.guild.region))

        should_connect = ctx.command.name in (
            'play', )  # Add commands that require joining voice to work.
        should_not_connect = ctx.command.name in ('lyrics', )

        if should_not_connect:
            return

        if not ctx.author.voice or not ctx.author.voice.channel:
            embed = discord.Embed(
                color=0xffa8e0,
                title="There was an error when attempting this action.",
                description="Make sure to be in a voice channel.")
            raise commands.CommandInvokeError(await ctx.send(embed=embed))

        if not player.is_connected:
            if not should_connect:
                embed = discord.Embed(
                    color=0xffa8e0,
                    title="There was an error when attempting this action.",
                    description="Bot is not connected to the voice chat.")
                raise commands.CommandInvokeError(await ctx.send(embed=embed))

            permissions = ctx.author.voice.channel.permissions_for(ctx.me)

            if not permissions.connect or not permissions.speak:  # Check user limit too?
                embed = discord.Embed(
                    color=0xffa8e0,
                    title="Insufficient permissions.",
                    description=
                    "Bot requires permissions to join voice channels as well as, permissions to be able to speak."
                )
                await ctx.send(embed=embed)

            player.store('channel', ctx.channel.id)
            await self.connect_to(ctx.guild.id,
                                  str(ctx.author.voice.channel.id))
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                embed = discord.Embed(
                    color=0xffa8e0,
                    title="First, do the following.",
                    description=
                    "Make sure you're on the same voice channel as your bot.")
                raise commands.CommandInvokeError(await ctx.send(embed=embed))
Example #22
0
 async def on_interaction_create(self, event: dict):
     if event['version'] != 1:
         raise RuntimeError(
             f'Interaction data version {event["version"]} is not supported'
             ', please open an issue for this: '
             'https://github.com/Kenny2github/discord-ext-slash/issues/new')
     for maybe_cmd in self.slash:
         if maybe_cmd.id == int(event['data']['id']):
             cmd = maybe_cmd
             break
     else:
         raise commands.CommandNotFound(
             f'No command {event["data"]["name"]!r} found')
     ctx = await cmd.coro.__annotations__[cmd._ctx_arg](self, cmd, event)
     try:
         await ctx.command.invoke(ctx)
     except commands.CommandError as exc:
         self.dispatch('command_error', ctx, exc)
     except asyncio.CancelledError:
         return
     except Exception as exc:
         try:
             raise commands.CommandInvokeError(exc) from exc
         except commands.CommandInvokeError as exc2:
             self.dispatch('command_error', ctx, exc2)
Example #23
0
 async def undo_step(self):
     params = {
         "callback": "",
         "session": self.aki_session,
         "signature": self.signature,
         "step": self.step,
         "answer": -1,
         "question_filter": "cat=1",  # NSFW filtering
         "_": int(time()),
     }
     async with self.bot.session.get(f"{self.api_url}/ws/answer",
                                     headers=self.common_headers,
                                     params=params) as req:
         response = loads(await req.text())
     if not response.get("completion"):
         raise ConnectionError(_("No results..."))
     if response["completion"] == "OK":
         try:
             self.step = int(response["parameters"]["step"])
             self.progress = round(
                 float(response["parameters"]["progression"]))
             question = response["parameters"]["question"]
             answers = response["parameters"]["answers"]
         except KeyError as e:
             await self.ctx.send(
                 _(":x: Response error (reason: `missing keys`)"),
                 delete_after=10)
             raise commands.CommandInvokeError(e)
         answer = await self.question_paginator(question, answers)
         await self.progress_check(answer)
     else:
         await self.error_handler(response["completion"])
Example #24
0
    async def update_repository(self, sha: str = None) -> Optional[dict]:
        """
        Update the repository from Modmail main repo.
        Parameters
        ----------
        sha : Optional[str], optional
            The commit SHA to update the repository.
        Returns
        -------
        Optional[dict]
            If the response is a dict.
        """
        if not self.username:
            raise commands.CommandInvokeError("Username not found.")

        if sha is None:
            resp: dict = await self.request(self.REPO + "/git/refs/heads/" +
                                            self.BRANCH)
            sha = resp["object"]["sha"]

        payload = {
            "base": self.BRANCH,
            "head": sha,
            "commit_message": "Updating bot"
        }

        merge_url = self.MERGE_URL.format(username=self.username)

        resp = await self.request(merge_url, method="POST", payload=payload)
        if isinstance(resp, dict):
            return resp
Example #25
0
    async def queue(self, ctx, page: int = 1):
        """Shows  the next 10 songs in the queue."""
        player = self.bot.music.player_manager.get(ctx.guild.id)
        if not player.queue:
            raise commands.CommandInvokeError('Nothing in queue')

        items_per_page = 10
        pages = math.ceil(len(player.queue) / items_per_page)

        if page <= 0:
            page = int(1)
        elif page > pages:
            page = int(pages)

        start = (page - 1) * items_per_page
        end = start + items_per_page

        queue_list = ''
        for index, track in enumerate(player.queue[start:end], start=start):
            queue_list += f'`{index + 1}.` [**{track.title}**]({track.uri})\n'

        if player.is_playing:
            embed = Embed(
                description=f'**{len(player.queue)} tracks**\n\n '
                f'Now playing: [{player.current.title}]({player.current.uri})\n\n{queue_list}'
            )
        else:
            embed = Embed(
                description=f'**{len(player.queue)} tracks**\n\n{queue_list}')
        embed.set_footer(text=f'Viewing page {page}/{pages}')
        await ctx.send(embed=embed)
Example #26
0
 async def ensure_voice(self, ctx):
     player = self.bot.lavalink.players.create(ctx.guild.id, endpoint=str(ctx.guild.region))
     should_connect = ctx.command.name in ('play')  
     if not ctx.author.voice or not ctx.author.voice.channel:
         raise commands.CommandInvokeError('먼저 음성 채널에 들어와주세요.')
     if not player.is_connected:
         if not should_connect:
             raise commands.CommandInvokeError('Not connected.')
         permissions = ctx.author.voice.channel.permissions_for(ctx.me)
         if not permissions.connect or not permissions.speak:  
             raise commands.CommandInvokeError('권한이 없습니다! (Connect, Speak 권한을 주세요!)')
         player.store('channel', ctx.channel.id)
         await self.connect_to(ctx.guild.id, str(ctx.author.voice.channel.id))
     else:
         if int(player.channel_id) != ctx.author.voice.channel.id:
             raise commands.CommandInvokeError('다른 음성 채널에 있어요! 제가 있는 음성 채널로 와주세요.')
Example #27
0
 async def channel(self, ctx, channel_id : int):
     channel = await self.client.fetch_channel(channel_id)
     
     if not channel.type == discord.ChannelType.text:
         raise commands.CommandInvokeError()
     self.client.connections[ctx.channel] = channel
     await response(messageable = ctx, text = f"channel is `{self.client.connections[ctx.channel]}`")
Example #28
0
    async def update_repository(self, sha: str = None) -> Optional[dict]:
        """
        Update the repository from Modmail main repo.

        Parameters
        ----------
        sha : Optional[str], optional
            The commit SHA to update the repository.

        Returns
        -------
        Optional[dict]
            If the response is a dict.
        """
        if not self.username:
            raise commands.CommandInvokeError("Username not found.")

        if sha is None:
            resp: dict = await self.request(self.HEAD)
            sha = resp['object']['sha']

        payload = {
            'base': 'master',
            'head': sha,
            'commit_message': 'Updating bot'
        }

        merge_url = self.MERGE_URL.format(username=self.username)

        resp = await self.request(merge_url, method='POST', payload=payload)
        if isinstance(resp, dict):
            return resp
Example #29
0
    async def ensure_voice(self, ctx):
        player = self.bot.music.player_manager.create(ctx.guild.id, endpoint=str(ctx.guild.region))

        should_connect = ctx.command.name in ('play')

        if not ctx.author.voice or not ctx.author.voice.channel:
            raise commands.CommandInvokeError('Для начала зайди в канал.')

        if not player.is_connected:
            if not should_connect:
                raise commands.CommandInvokeError('Не подключен.')

            player.store('channel', ctx.channel.id)
            await ctx.guild.change_voice_state(channel=ctx.author.voice.channel)
        else:
            if int(player.channel_id) != ctx.author.voice.channel.id:
                raise commands.CommandInvokeError('Ты не в том канале.')
Example #30
0
 async def ensure_voice(self, ctx):
     if not ctx.author.voice or not ctx.author.voice.channel:
         # Our cog_command_error handler catches this and sends it to the voicechannel.
         # Exceptions allow us to "short-circuit" command invocation via checks so the
         # execution state of the command goes no further.
         raise commands.CommandInvokeError(
             'Bir Ses Kanalına Bağlanmalısın!')
     """