async def status(self, *status:str): '''Change bot status. Usage: status "text here" ''' status = ' '.join(status) await self.bot.change_presence(game=discord.Game(name=status)) load_redis().rpush("status",status) print(load_redis().lrange("status",0,-1)) print(random.choice(load_redis().lrange("status",0,-1))) em = discord.Embed(description='Changing status to: {}'.format(status), colour=0x66FF66) await self.bot.say(embed=em)
async def add(self, ctx, keyword): config = load_redis() config.rpush("drama", keyword) em = discord.Embed( description='**{0}** added to drama keywords.'.format(keyword), colour=0x66FF66) await self.bot.say(embed=em)
async def colour(self, ctx, colour:discord.Colour): '''Change your colour. Usage: colour hex_value ''' try: bot_channel = self.bot.get_channel(load_redis().hget(ctx.message.server.id, "botchannel").decode('utf-8')) r = colour.r/255 g = colour.g/255 b = colour.b/255 c = Color(rgb=(r, g, b)) if c.luminance < 0.45: c.luminance = 0.45 if c.saturation > 0.80: c.saturation = 0.80 colour_new = discord.Colour(int(c.hex[1:], 16)) if colour.value != colour_new.value: colour = colour_new em = discord.Embed(description='{0} your colour has been adjusted to look better on discord. New colour: {1}'.format(ctx.message.author.mention,c.hex), colour=colour) await self.bot.send_message(bot_channel, embed=em) role = discord.utils.find(lambda r: r.name.startswith(str(ctx.message.author)), list(ctx.message.server.roles)) em = discord.Embed(description='New color set for {0}'.format(ctx.message.author.mention), colour=colour) if role: await self.bot.edit_role(ctx.message.server,role,colour=colour) await self.bot.add_roles(ctx.message.author,role) await self.bot.send_message(bot_channel, embed=em) else: await self.bot.create_role(ctx.message.server,name=str(ctx.message.author),colour=colour) await asyncio.sleep(2) role = discord.utils.find(lambda r: r.name.startswith(str(ctx.message.author)), list(ctx.message.server.roles)) await self.bot.add_roles(ctx.message.author, role) await self.bot.send_message(bot_channel, embed=em) except Exception as e: await self.bot.say(embed=discord.Embed(title=self.err_title, description=str(e), colour=self.colourRed))
async def bots(self, ctx, channel_name): channel = discord.utils.find(lambda r: r.name.startswith(channel_name), list(ctx.message.server.channels)) config = load_redis() config.hset(ctx.message.server.id, 'botchannel', channel.id) em = discord.Embed(description='**{0}** saved as bots channel.'.format( channel.name), colour=0x66FF66) await self.bot.say(embed=em)
async def drama(self, ctx): '''Check the drama level. Usage: drama ''' keywords = load_redis().lrange("drama", 0, -1) list = [x.decode('utf-8') for x in keywords] print(list) drama_count = 0 async for msg in self.bot.logs_from(ctx.message.channel, before=ctx.message, limit=500): if any(key in msg.content.lower() for key in list): drama_count += 1 print(drama_count) await self.bot.say("Drama factor in *{0}*: **{1}%**".format( ctx.message.channel, int(drama_count) * 100 / 500))
async def gelbooru(self, ctx, *tags: str): '''Get random gelbooru image with given tags. Usage: gelbooru "tags" ''' nsfw_channel_id = load_redis().hget(ctx.message.server.id, "nsfwchannel").decode('utf-8') try: tags = ' '.join(tags) self.bot.send_typing(self.bot.get_channel(nsfw_channel_id)) response = requests.get( "http://gelbooru.com/?page=dapi&s=post&q=index&tags={0}". format(tags)) root = ElementTree.fromstring(response.content) random_post_number = random.randint(1, len(root.getchildren())) random_post = root[random_post_number] img_link = random_post.attrib["file_url"] if ctx.message.channel == self.bot.get_channel(nsfw_channel_id): em = discord.Embed( description='**Score:** {0} \n **Direct link:** http:{1}'. format(random_post.attrib["score"], img_link), colour=0x66FF66) else: em = discord.Embed( description= 'Here is your image {0} \n **Score:** {1} \n **Direct link:** http:{2}' .format(ctx.message.author.mention, random_post.attrib["score"], img_link), colour=0x66FF66) em.set_image(url="http:{0}".format(img_link)) em.set_author( name="Gelbooru: {0}".format(tags), icon_url= "http://ai-i1.infcdn.net/icons_siandroid/jpg/300/4687/4687752.jpg" ) await self.bot.send_message(self.bot.get_channel(nsfw_channel_id), embed=em) except Exception as e: await self.bot.say(embed=discord.Embed(title=self.err_title, description=str(e), colour=self.colourRed))
async def danbooru(self, ctx, *tags: str): '''Get random danbooru image with given tags. Usage: danbooru "tags" ''' nsfw_channel_id = load_redis().hget(ctx.message.server.id, "nsfwchannel").decode('utf-8') try: tags = ' '.join(tags) self.bot.send_typing(self.bot.get_channel(nsfw_channel_id)) response = requests.get( "http://danbooru.donmai.us/post/index.json?tags={0}".format( tags)).json() random_image = random.choice(response) if ctx.message.channel == self.bot.get_channel(nsfw_channel_id): em = discord.Embed( description= '**Score:** {0} \n **Direct link:** http://danbooru.donmai.us{1}' .format(random_image["score"], random_image["file_url"]), colour=0x66FF66) else: em = discord.Embed( description= 'Here is your image {0} \n **Score:** {1} \n **Direct link:** http://danbooru.donmai.us{2}' .format(ctx.message.author.mention, random_image["score"], random_image["file_url"]), colour=0x66FF66) em.set_image(url="http://danbooru.donmai.us{0}".format( random_image["file_url"])) em.set_author( name="Danbooru: {0}".format(tags), icon_url= "http://ai-i1.infcdn.net/icons_siandroid/jpg/300/4687/4687752.jpg" ) await self.bot.send_message(self.bot.get_channel(nsfw_channel_id), embed=em) except Exception as e: await self.bot.say(embed=discord.Embed(title=self.err_title, description=str(e), colour=self.colourRed))