async def checks(ctx, member, command): if member is None: await ctx.send( **em(f"Please specify a member you want to {command}!")) return False elif member == ctx.author: await ctx.send(**em(f"You cant {command} yourself!")) return False return True
async def trigger(self, ctx, *, trigger: str): """Triggers a support keyword.""" try: response = get_support()[trigger] await ctx.send(**em(response["response"])) except KeyError: closest = get_close_matches( trigger, [str(item).lower() for item in get_support()]) extra = f"Did you mean `{'`, `'.join(closest)}`?" if closest else "" await ctx.send( **em(f"Did not find any matching trigger keys.\n{extra}"))
async def push_commit(self, commit): title = f"[{commit['repo']}] {len(commit['commits'])} new commits." for channel in [ self.bot.get_channel(channel_id) for channel_id in update_channels() ]: await channel.send(**em(title=title, content=commit["changes"]))
async def rules(self, ctx): await ctx.send(**em( content= "Hello, newlings!\nFirst of all welcome to the official `Discord Marketplace` server!\n" "This server will provide support for any questions you might have about the platform.\n" "If you want to add a bot/server or ad of your own, it’s highly recommended to be in this discord server.\n" "To make sure nothing happens, please read ‘__**Information**__’ and ‘__**Rules**__’!", fields=[ field( "Information", "Breaking any of these rules may result in a punishment.\n" "You should always listen to the role above you. *(`Member` < `Management` < `Senior Management` < `Founder`)*", False), field( "Rules", "**#1** | Don’t ask for free stuff!\n" "**#2** | Follow the channel guidelines!\n" "**#3** | Do not harras/insult other members! (includes staff)\n" "**#4** | No toxicity is allowed!\n" "**#5** | No swearing!\n" "**#6** | No kind of NSFW content is allowed!\n" "**#7** | Only speak English or Dutch in <#688853503875088576>, if you want to speak another language go to <#688853522330026031>!\n" "**#8** | No chat/voice spamming/caps/zalgo is allowed!\n" "**#9** | No political arguments/discussions.\n" "**#10** | Listen to staff. (think the staff is abusing this? DM <@232182858251239424>)", False) ], footer_message="Discord Marketplace | Information & Rules", timestamp=False))
async def on_command_error(self, ctx, error): if isinstance(error, discord.NotFound): return elif isinstance(error, (discord.Forbidden, discord.errors.Forbidden)): pass elif isinstance(error, (TypeError, commands.MissingRequiredArgument)): await ctx.send(**em( layout="error", content= f"Missing argument(s) for the '{ctx.command.qualified_name}' command.\n" f"Use the command like this:\n{get_prefix(self.bot, ctx.message, True)}" f"{ctx.command.qualified_name} {' '.join(ctx.command.clean_params)}" )) elif isinstance(error, commands.MissingAnyRole): await ctx.send(**em( content="You are missing the required permissions/role!")) else: raise error
async def on_member_join(self, member): if await self.send_join_leave(member): await member.add_roles(*self.verify_roles) await member.add_roles(*self.join_roles) try: await member.send(**em( f"Thanks for joining `{self.main_server.name}`, have a great time here!" )) except discord.errors.Forbidden: pass
async def on_raw_reaction_add(self, payload): if self.main_server is None: return if payload.guild_id == int(self.server) and payload.channel_id == int( self.verify_channel): await payload.member.remove_roles(*self.verify_roles) await self.log.send_verified(payload.member.id) await payload.member.send(**em( f"You successfully verified yourself in `{self.main_server.name}`." ))
async def send_join_leave(self, member, join=True): if self.main_server is None and self.join_leave is None: return False if member.bot and join: await member.add_roles( self.main_server.get_role(688802297500794900)) await self.log.send_bot_add(member) return False await self.join_leave.send( member.mention if join else "", **em( config["GENERAL"]["welcomeMSG" if join else "leaveMSG"].format( member=member, nl="\n", verify=self.verify_channel))) return True
async def on_message(self, message): if message.author.bot: return if message.channel.id == int(config["SUPPORT"]["support-c"]): ctx = await self.bot.get_context(message) if not ctx.valid: keywords = get_support() for cat in keywords: msg = em( fields=[ field("Automated response:", keywords[cat]["response"], False) ], content= f"This is an auto response.\nIf this isn't right we're sorry." ) for word in message.content.lower().split(" "): found = get_close_matches(word, keywords[cat]["keywords"]) if found: return await ctx.send(ctx.author.mention, **msg) for keyword in keywords[cat]["keywords"]: if keyword in str(message.content).lower(): return await ctx.send(ctx.author.mention, **msg)
async def kick(self, ctx, member: discord.Member = None, *, reason="Undefined"): if 688802497006927924 in [role.id for role in member.roles]: return await ctx.send(**em("You can't kick server bots!")) if await self.checks(ctx, member, "kick"): if [ i for i in [role.id for role in member.roles] if i in self.all_perms ]: return await ctx.send(**em( "This user is currently in the management team.\n" "If you would like to kick/remove this user from the server the demotion protocol should be used.\n" "If you are a member of the management team you are unable to do this and if you have something against a member from the management team please contact a member of the senior management team." )) msg = await ctx.send(**em( content=f"Are you sure you want to kick {member.mention}?\n" f"Reason for kick:\nReason:\n```\n{reason.strip()}\n```", fields=[ field( f"{member}'s information:", f"User roles: {', '.join(sorted([role.mention for role in member.roles if role.name != '@everyone']))}" ) ])) await msg.add_reaction("✅") await msg.add_reaction("❌") def check(_reaction, _user): return _user == ctx.author and (str(_reaction.emoji) == "✅" or str(_reaction.emoji) == "❌") try: reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=check) except asyncio.TimeoutError: try: await msg.edit( **em("You didn't react or to late. *(60s+)*")) except discord.errors.NotFound: await ctx.send( **em("You didn't react or to late. *(60s+)*")) await msg.clear_reactions() else: if str(reaction) == "✅": if not member.bot: try: await member.send(**em( f"Hey {member.mention}!\n" f"Unfortunately you have been kicked from `{ctx.guild.name}`.\n" f"You got kicked by {ctx.author.mention} [{ctx.author.top_role.name}] (`{ctx.author.id}`).\n" f"The reason for the kick was the following:\n```\n{reason.strip()}\n```" )) except discord.errors.Forbidden: pass await member.kick(reason=reason) log_obj = Log('kick', member, ctx.author, reason.strip()) log = await self.log.send_log(log_obj) log_obj.id = str(log.id) await self.log.edit_log(log, log_obj) try: await msg.edit(**em( f"Successfully kicked {member}!\nReason:\n```\n{reason.strip()}\n```" )) except discord.errors.NotFound: await ctx.send(**em( f"Successfully kicked {member}!\nReason:\n```\n{reason.strip()}\n```" )) await msg.clear_reactions() else: try: await msg.edit(**em("Stopped the kicking protocol!")) except discord.errors.NotFound: await ctx.send(**em("Stopped the kicking protocol!")) await msg.clear_reactions()
async def embed(self, ctx, *, message): await ctx.send(**em(self.user_content(ctx, message), footer_message=f"Send by {ctx.author}", footer_icon=ctx.author.avatar_url, timestamp=False))