Exemplo n.º 1
0
class Imgur:
    def __init__(self, bot):
        self.bot = bot

        self.imgur_client = ImgurClient(IMGUR_CLIENT_ID, IMGUR_CLIENT_SECRET)

    @commands.command()
    async def imgur(self, ctx, *, search: str = None):
        await ctx.trigger_typing()
        try:
            if search is not None:
                images = self.imgur_client.gallery_search(search)
                image = choice(images)
                if await self.nsfw_check(image, ctx.message.channel) is True:
                    await ctx.send(image.link)
            else:
                await ctx.send('No search query set.')
        except IndexError as e:
            await ctx.send('Nothing found for: {}'.format(search))

    @commands.command()
    async def memes(self, ctx):
        try:
            await ctx.trigger_typing()
            images = self.imgur_client.default_memes()
            image = choice(images)
            if await self.nsfw_check(image, ctx.message.channel) is True:
                await ctx.send(image.link)
        except IndexError as e:
            await ctx.send('Error: Nothing found.')

    @commands.command(pass_context=True)
    async def sr(self, ctx, *, search: str):
        await ctx.trigger_typing()
        try:
            if search is not None:
                images = self.imgur_client.subreddit_gallery(search)
                image = choice(images)
                if await self.nsfw_check(image, ctx.message.channel) is True:
                    await ctx.send(image.link)
            else:
                await ctx.send('No search query set.')
        except IndexError as e:
            await ctx.send('Nothing found for: {}'.format(search))

    async def nsfw_check(self, image, channel):
        if image.nsfw is False:
            return True
        elif image.nsfw is True and channel.is_nsfw():
            return True
        await channel.send(
            '**NSFW Picture**: Please only lookup nsfw content in **nsfw** channels.'
        )
        return False
Exemplo n.º 2
0
 async def on_message(self, message):
     if message.author == self.user:
         return
     elif message.content[0] == prefix:
         command = message.content[1:].split()
         if command[0].lower() in ['lvl', 'level']:
             session = db_session.create_session()
             user = session.query(User).filter(
                 User.name == str(message.author))[0]
             await message.channel.send(
                 f'Ваш уровень: {user.lvl}, {user.xp}/{(user.lvl + 1) * 100} xp'
             )
             session.commit()
         elif command[0].lower() in ['leaderboard', 'top']:
             session = db_session.create_session()
             users = session.query(User).all().sort()
             if len(users) > 10:
                 users = users[:10]
             m = ''
             for user in users:
                 m += f'{user.name[:-5]}: {user.lvl} lvl, {user.xp}/{(user.lvl + 1) * 100} xp\n'
             await message.channel.send(m)
         elif command[0].lower() == 'play':
             self.vc = message.author.voice
             if self.vc is None:
                 await message.channel.send(
                     'Вы не подключены к голосовому каналу')
             else:
                 await message.channel.send(' '.join(command[1:]) +
                                            ' Добавлено в очередь')
                 await self.queue.put([command[1:], message.channel])
         elif command[0].lower() == 'song':
             await message.channel.send(self.track.title)
         elif command[0].lower() == 'stop':
             while not self.queue.empty():
                 self.queue.get_nowait()
             await self.player.disconnect()
         # -meme СКОРЕЕ ВСЕГО НЕ РАБОТАЕТ, ПОКА НЕ ПРОВЕРЯЛ
         elif command[0].lower() == 'meme':
             client_id = '5d6d51c3b6b7dc2'
             client_secret = '5a419654aae91de31d31a6697f3f07ff1d952748'
             client = ImgurClient(client_id, client_secret)
             embed = discord.Embed()
             embed.set_image(url=client.default_memes())
             await message.channel.send(embed=embed)
     session = db_session.create_session()
     user = session.query(User).filter(User.name == str(message.author))[0]
     user.xp += randint(7, 13)
     if user.xp >= (user.lvl + 1) * 100:
         user.lvl += 1
         user.xp = 0
     session.commit()