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 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_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")
async def sync_member_roles(self, member): channel = self.bot.get_channel(675742172015755274) try: badges = await self.bot.db.fetchval( "SELECT flags FROM badges WHERE _id = $1", member.id) if not badges: return try: early = member.guild.get_role(679642623107137549) partner = member.guild.get_role(683288670467653739) booster = member.guild.get_role(686259869874913287) verified = member.guild.get_role(733817083330297959) bugs = member.guild.get_role(679643117510459432) sponsor = member.guild.get_role(779299456125763584) flags = publicflags.BotFlags(badges) for badge in [*flags]: if badge in ['early', 'early_supporter']: await member.add_roles(early) elif badge == 'bot_partner': await member.add_roles(partner) elif badge == 'donator': await member.add_roles(booster) elif badge in ['bug_hunter_lvl1', 'bug_hunter_lvl2']: await member.add_roles(bugs) elif badge == 'sponsor': await member.add_roles(sponsor) except KeyError: pass except Exception as error: tb = traceback.format_exception(type(error), error, error.__traceback__) tbe = "".join(tb) + "" e = discord.Embed( color=discord.Color.red(), title= 'Error Occured whilst trying to add a role to new member!') e.description = tbe await channel.send( embed=e, content= f"Failed to add roles for {member.mention} `({member.name} - {member.id})`" ) except Exception as e: await channel.send( f"Error occured when trying to add the role: {e}")
async def partner_remove_bot(self, ctx, bot: typing.Union[discord.User, str], *, reason: str): bot = await default.find_user(ctx, bot) if not bot: return await ctx.send("Couldn't find a bot with that name or id.") elif not bot.bot: return await ctx.send("Please provide me a bot, not a normal user") else: check = await self.bot.db.fetch("SELECT message_id, _id FROM partners WHERE bot_id = $1", bot.id) if not check: return await ctx.send(f"{bot} doesn't seem to be a partner.") support_server = self.bot.get_guild(671078170874740756) partner_channel = support_server.get_channel(698903601933975625) partner_main_chat = support_server.get_channel(741816038257197187) partner_role = support_server.get_role(683288670467653739) with suppress(discord.errors.NotFound): msg = await partner_channel.fetch_message(check[0]['message_id']) await msg.delete() member = self.bot.get_guild(671078170874740756).get_member(check[0]['_id']) if member: if partner_role in member.roles: await member.remove_roles(partner_role, reason="Not a partner anymore.") with suppress(Exception): await member.send("Unfortunately, we've decided to no longer be partners with you, sorry for the inconvenience and thanks for being our partner until now :)" f"\n**Reason:** {reason}") badges = await self.bot.db.fetchval("SELECT * FROM badges WHERE _id = $1", check[0]['_id']) flags = publicflags.BotFlags(badges) if 'bot_partner' in [*flags] and badges: await self.bot.db.execute("UPDATE badges SET flags = flags - 4 WHERE _id = $1", check[0]['_id']) mongo_db = self.bot.mongo.get_database('website') mongo_db.partners.delete_one({"partner_bot": bot.id}) await self.bot.db.execute('DELETE FROM partners WHERE bot_id = $1', bot.id) await partner_main_chat.send(f"{bot} has been removed from my partner's list for `{reason}`") await ctx.send(f"Successfully removed {bot} from my partners list.")
async def partner_add_server(self, ctx, member: discord.Member): try: message = await ctx.channel.send("Have you verified if Dredd is in the server?", delete_after=60) reactions = ['<:yes:820339603722600470>', '<:no:820339624849178665>'] for reaction in reactions: await message.add_reaction(reaction) in_guild, valid = None, None while True: reaction, user = await self.bot.wait_for('reaction_add', check=lambda r, m: r.message.id == message.id and m.id == ctx.author.id, timeout=60) if str(reaction) == '<:yes:820339603722600470>': in_guild, valid = True, True await message.delete() break elif str(reaction) == '<:no:820339624849178665>': in_guild = False await message.delete() break else: await message.remove_reaction(str(reaction)) continue guild, invite = None, None if not in_guild: message = await ctx.channel.send("Please send a permanent invite to the server if you want to validate the partnership without Dredd being in that server.") while True: message = await self.bot.wait_for('message', check=lambda m: m.channel.id == ctx.channel.id and m.author.id == ctx.author.id, timeout=60) if message.content.lower() == 'cancel': break try: guild = await self.bot.fetch_invite(message.content) invite = guild.url guild = guild.guild.id break except Exception as e: await ctx.channel.send(f"Error occured: `{e}`") continue if not guild: return elif in_guild: message = await ctx.channel.send("Please send an ID of the server you want to partner") while True: message = await self.bot.wait_for('message', check=lambda m: m.channel.id == ctx.channel.id and m.author.id == ctx.author.id, timeout=60) if message.content.lower() == 'cancel': break database_check = await self.bot.db.fetchval("SELECT * FROM guilds WHERE guild_id = $1", int(message.content)) if not database_check: await ctx.channel.send("Dredd doesn't seem to be in that server. Please make sure the id is correct") continue else: guild = int(message.content) break if not guild: return check_partner = await self.bot.db.fetchval("SELECT * FROM partners WHERE _id = $1", guild) if check_partner: return await ctx.send("That guild is already a partner.") await ctx.send("Send a partner message that should be sent to the partners channel. (must be shorter than 1500 characters)") while True: message = await self.bot.wait_for('message', check=lambda m: m.channel.id == ctx.channel.id and m.author.id == ctx.author.id, timeout=60) if len(message.content) > 1500: await ctx.channel.send(f"Message is {len(message.content) - 1500} characters longer than the limit, please shorten it.", delete_after=5) continue elif len(message.content) < 1500: send_message = message.content await message.delete() break e = discord.Embed(color=5622378, title="Please verify the message is correct", description=send_message) e.add_field(name='Guild information:', value=f"**Guild:** {guild}") reactions = ['<:yes:820339603722600470>', '<:no:820339624849178665>'] message = await ctx.channel.send(content=f"{ctx.author.mention} - {member.mention}", embed=e, allowed_mentions=discord.AllowedMentions(users=True)) for reaction in reactions: await message.add_reaction(reaction) while True: reaction, user = await self.bot.wait_for('reaction_add', check=lambda r, m: r.message.id == message.id and m.id in [ctx.author.id, member.id], timeout=60) if str(reaction) == '<:yes:820339603722600470>': break elif str(reaction) == '<:no:820339624849178665>': return await ctx.channel.send("Cancelled the command.") else: await message.remove_reaction(str(reaction)) continue support_server = self.bot.get_guild(671078170874740756) partner_channel = support_server.get_channel(698903601933975625) partner_role = support_server.get_role(683288670467653739) new_partners_notif = support_server.get_role(741749103280783380) partner_main_chat = support_server.get_channel(741816038257197187) badges = await self.bot.db.fetchval("SELECT flags FROM badges WHERE _id = $1", member.id) flags = publicflags.BotFlags(badges) if badges and 'bot_partner' not in [*flags]: await self.bot.db.execute("UPDATE badges SET flags = flags + 4 WHERE _id = $1", member.id) elif not badges: await self.bot.db.execute("INSERT INTO badges(_id, flags) VALUES($1, $2)", member.id, 4) else: print('something') pass if member and partner_role not in member.roles: await member.add_roles(partner_role, reason='user is now a our partner!') await partner_main_chat.send(f"<:p_:748833273383485440> Welcome **{member.mention}** to our servers partners list!", allowed_mentions=discord.AllowedMentions(users=True)) message = await partner_channel.send(f"{new_partners_notif.mention}\n\n{send_message}", allowed_mentions=discord.AllowedMentions(roles=True)) if invite: que = "INSERT INTO partners(_id, type, message, time, message_id, valid, invite) VALUES($1, $2, $3, $4, $5, $6, $7)" await self.bot.db.execute(que, guild, 1, message.content[24:], datetime.utcnow(), message.id, valid, invite) else: que = "INSERT INTO partners(_id, type, message, time, message_id) VALUES($1, $2, $3, $4, $5)" await self.bot.db.execute(que, guild, 1, message.content[24:], datetime.utcnow(), message.id) try: await member.send("<:p_:748833273383485440> Congratulations! We're officially partners now!" "\nI've added a badge to your badges (you can see them in `-badges`), you can also see your partnering information in `-partnerslist`.") except Exception: pass await ctx.channel.send("Done!~") except asyncio.TimeoutError: return await ctx.send("You took too long, cancelling the command.") except Exception as e: return await ctx.send(e)
async def partner_add_bot(self, ctx, member: discord.Member, bot: typing.Union[discord.User, str]): bot = await default.find_user(ctx, bot) if member.bot: return await ctx.send(f"<:warning:820339642884030475> {member} is a bot. Please provide a non-bot user id.") if not bot.bot: return await ctx.send(f"<:warning:820339642884030475> {bot} is not a bot. Please provide a bot user id.") part_check = await self.bot.db.fetchval("SELECT * FROM partners WHERE bot_id = $1", bot.id) if part_check: return await ctx.send(f"<:warning:820339642884030475> {bot} is already partnered.") try: support_server = self.bot.get_guild(671078170874740756) partner_channel = support_server.get_channel(698903601933975625) partner_role = support_server.get_role(683288670467653739) new_partners_notif = support_server.get_role(741749103280783380) partner_member = support_server.get_member(member.id) partner_main_chat = support_server.get_channel(741816038257197187) await ctx.channel.send("Please send a partner message (must be shorter than 1500 characters)") while True: message = await self.bot.wait_for('message', check=lambda m: m.channel.id == ctx.channel.id and m.author.id == ctx.author.id, timeout=60) if len(message.content) > 1500: await ctx.channel.send(f"Message is {len(message.content) - 1500} characters longer than the limit, please shorten it.", delete_after=5) continue elif len(message.content) < 1500: send_message = message.content await message.delete() break e = discord.Embed(color=5622378, title="Please verify the message is correct", description=send_message) e.add_field(name='Bot information:', value=f"**Name & ID:** {bot} ({bot.id})\n**Created:** {btime.human_timedelta(bot.created_at.replace(tzinfo=None))}") reactions = ['<:yes:820339603722600470>', '<:no:820339624849178665>'] message = await ctx.channel.send(content=f"{ctx.author.mention} - {member.mention}", embed=e, allowed_mentions=discord.AllowedMentions(users=True)) for reaction in reactions: await message.add_reaction(reaction) while True: reaction, user = await self.bot.wait_for('reaction_add', check=lambda r, m: r.message.id == message.id and m.id in [ctx.author.id, member.id], timeout=60) if str(reaction) == '<:yes:820339603722600470>': break elif str(reaction) == '<:no:820339624849178665>': return await ctx.channel.send("Cancelled the command.") else: await message.remove_reaction(str(reaction)) badges = await self.bot.db.fetchval("SELECT flags FROM badges WHERE _id = $1", member.id) flags = publicflags.BotFlags(badges) if badges and 'bot_partner' not in [*flags]: await self.bot.db.execute("UPDATE badges SET flags = flags + 4 WHERE _id = $1", member.id) elif not badges: await self.bot.db.execute("INSERT INTO badges(_id, flags) VALUES($1, $2)", member.id, 4) else: pass if partner_member and partner_role not in partner_member.roles: await partner_member.add_roles(partner_role, reason='user is now a our partner!') await partner_main_chat.send(f"<:p_:748833273383485440> Welcome **{member.mention}** to our bot partners list!", allowed_mentions=discord.AllowedMentions(users=True)) message = await partner_channel.send(f"{new_partners_notif.mention}\n\n{send_message}", allowed_mentions=discord.AllowedMentions(roles=True)) await self.bot.db.execute("INSERT INTO partners(_id, type, message, time, bot_id, message_id) VALUES($1, $2, $3, $4, $5, $6)", member.id, 0, message.content[24:], datetime.utcnow(), bot.id, message.id) mongo_db = self.bot.mongo.get_database('website') mongo_db.partners.insert_one({ 'partner_user': member.id, 'partner_bot': bot.id, 'short_msg': "No message set...", 'website': "https://discord.com/oauth2/authorize?client_id={0}&scope=bot&permissions=0".format(bot.id), 'partner_since': datetime.utcnow(), 'html': "No description set..." }) try: await member.send("<:p_:748833273383485440> Congratulations! We're officially partners now!" "\nI've added a badge to your badges (you can see them in `-badges`), you can also see your partnering information in `-partnerslist`. " "To get your information updated on the site (https://dreddbot.xyz/partners) please DM Moksej a short brief (<150 chars), " "long description (html), link to website/docs/anything you want.") except Exception: pass await ctx.channel.send("Done!~") except asyncio.TimeoutError: return await ctx.send("You ran out of time.") except Exception as e: print(traceback.format_exception(type(e), e, e.__traceback__)) return await ctx.send(e)