async def addbadge_server(self, ctx, server: int, badge: str): guild = self.bot.get_guild(server) if not guild: return await ctx.send(f"{self.bot.settings['emojis']['misc']['warn']} | Server not found") attr = getattr(self.bot, 'settings') try: attr['emojis']['ranks'][badge] except Exception as e: e = discord.Embed(color=self.bot.settings['colors']['deny_color'], title='Invalid badge') badges = 'Those are the valid ones:\n' for badge in attr['emojis']['ranks']: badges += f'`{badge}`, ' e.description = badges[:-2] return await ctx.send(embed=e) badges = CM.get(self.bot, 'badges', guild.id) if getattr(publicflags.BotFlags(badges if badges else 0), badge): return await ctx.send(f"**{guild}** already has {attr['emojis']['ranks'][badge]}") else: badge_value = default.badge_values(ctx) if badges: self.bot.badges[guild.id] += badge_value[badge] await self.bot.db.execute("UPDATE badges SET flags = flags + $1 WHERE _id = $2", badge_value[badge], guild.id) else: self.bot.badges[guild.id] = badge_value[badge] await self.bot.db.execute("INSERT INTO badges(_id, flags) VALUES($1, $2)", guild.id, badge_value[badge]) await ctx.send(f"Added {attr['emojis']['ranks'][badge]} to {guild} badges")
async def removebadge_server(self, ctx, server: int, badge: str): guild = self.bot.get_guild(server) if not guild: return await ctx.send(f"{self.bot.settings['emojis']['misc']['warn']} | Server not found") attr = getattr(self.bot, 'settings') try: attr['emojis']['ranks'][badge] except Exception as e: e = discord.Embed(color=self.bot.settings['colors']['deny_color'], title='Invalid badge') badges = 'Those are the valid ones:\n' for badge in attr['emojis']['ranks']: badges += f'`{badge}`, ' e.description = badges[:-2] return await ctx.send(embed=e) badges = CM.get(self.bot, 'badges', guild.id) if not getattr(publicflags.BotFlags(badges if badges else 0), badge): return await ctx.send(f"**{guild}** doesn't have {attr['emojis']['ranks'][badge]} badge") else: badge_value = default.badge_values(ctx) self.bot.badges[guild.id] -= badge_value[badge] await self.bot.db.execute("UPDATE badges SET flags = flags - $1 WHERE _id = $2", badge_value[badge], guild.id) await ctx.send(f"Removed {attr['emojis']['ranks'][badge]} from {guild} badges")
async def removebadge_user(self, ctx, user: typing.Union[discord.User, str], badge: str): user = await default.find_user(ctx, user) if not user: return await ctx.send(f"{ctx.bot.settings['emojis']['misc']['warn']} | User could not be found") attr = getattr(self.bot, 'settings') try: attr['emojis']['ranks'][badge] except Exception as e: e = discord.Embed(color=self.bot.settings['colors']['deny_color'], title='Invalid badge') badges = 'Those are the valid ones:\n' for badge in attr['emojis']['ranks']: badges += f'`{badge}`, ' e.description = badges[:-2] return await ctx.send(embed=e) badges = CM.get(self.bot, 'badges', user.id) if not getattr(publicflags.BotFlags(badges if badges else 0), badge): return await ctx.send(f"**{user}** doesn't have {attr['emojis']['ranks'][badge]} badge") else: badge_value = default.badge_values(ctx) self.bot.badges[user.id] -= badge_value[badge] await self.bot.db.execute("UPDATE badges SET flags = flags - $1 WHERE _id = $2", badge_value[badge], user.id) await ctx.send(f"Removed {attr['emojis']['ranks'][badge]} from {user} badges")