示例#1
0
    async def byRandom(self, ctx: commands.Context):
        archive = getArchiveFromContext(ctx)

        archiveChannel: discord.TextChannel = await fetchChannel(
            ctx.guild, archive.channelID)
        post = archive.getRandomPost()
        attempts = 100
        while True:
            try:
                message: discord.Message = await archiveChannel.fetch_message(
                    post.messageID)

                author: discord.Member = await ctx.guild.fetch_member(
                    post.authorID)
                if not author: raise discord.DiscordException()
                break
            except discord.DiscordException:
                post = archive.getRandomPost()

            attempts -= 1
            if attempts <= 0:
                await fail(R.byRandom.error)

        story = post.getRandomStory()
        await ctx.send(embed=getLaprOSEmbed(**R.byRandom.embed(
            story.title, author.display_name, story.summary, message.jump_url))
                       )
示例#2
0
    def __init__(self, bot: commands.Bot, pack):
        """
        Constructor for StaticRoleMenu.

        Args:
            bot(commands.Bot): pass in bot reference for processing
            pack: data received from database
        """
        self.name = pack['name']
        self.active = pack['active']
        self.guild = pack['guild_id']
        self.target = pack['message_id']
        self.channel = pack['channel_id']
        self.custom = pack['custom']
        self.raw = pack['emote']
        self.multiple = pack['multi']
        self.hidden = []
        if not self.target or not self.channel:
            self.active = False
        self.data = {}
        self.error = []
        guild = bot.get_guild(pack['guild_id'])
        if not guild:
            raise discord.DiscordException("Can't find the given guild")
        else:
            for i in range(len(pack['custom'])):
                role = guild.get_role(pack['role_id'][i])
                emote = bot.get_emoji(
                    int(pack['emote']
                        [i])) if pack['custom'][i] else pack['emote'][i]
                if role and emote:
                    self.hidden.append(emote)
                    self.data.update({str(pack['emote'][i]): role})
                else:
                    self.error.append(pack['role_id'][i])
示例#3
0
    async def set_volume(self, ctx, volume):
        player = self.bot.wavelink.get_player(ctx.guild.id)

        try:
            if volume > 1000:
                await ctx.send("Set the volume between 0 and 200")
            elif volume < 1000:
                await player.set_volume(volume)
        except:
            await ctx.send("I couldn't change the volume.. for some reason :/")
            raise discord.DiscordException("Failed to change volume")
示例#4
0
    async def leave(self, ctx, channel: discord.VoiceChannel=None):
        if not channel:
            try:
                channel = ctx.author.voice.channel
            except AttributeError:
                await ctx.send("I'm not in a voice channel!")
                raise discord.DiscordException("User executed leave command without the yama ever joining in.. :pepega:")

            player = self.bot.wavelink.get_player(ctx.guild.id)
            await player.disconnect()
            await ctx.send(f"I've left **{channel.name}**")
示例#5
0
    async def join(self, ctx, *, channel: discord.VoiceChannel = None):
        """Connect to a voice channel."""
        if not channel:
            try:
                channel = ctx.author.voice.channel
            except AttributeError:
                raise discord.DiscordException(
                    'Tu n\'est pas dans un salon vocal !')

        player = self.bot.wavelink.get_player(ctx.guild.id)
        await ctx.send(f'Je rejoins **`{channel.name}`** !')
        await player.connect(channel.id)