async def modlog(self, ctx): """ Return moderation log of a member """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) if member is None: full_name = args[0] else: full_name = get_full_name(ctx.message.author) embed = discord.Embed( title=full_name, color=config.COLOR, ) for log_entry in db["logs"]["logs"]: if log_entry["userid"] == int(args[0]): if log_entry["type"] in ["warn", "kick"]: embed.add_field( name=log_entry["type"].capitalize(), value=( f"Time: {log_entry['day']}/{log_entry['month']}/{log_entry['year']} " + \ f"{log_entry['hour']}:{log_entry['minute']}\n" + \ f"Reason: {log_entry['reason']}" ), inline=False, ) else: embed.add_field( name=log_entry["type"].capitalize(), value=( f"Time: {log_entry['day']}/{log_entry['month']}/{log_entry['year']} " + \ f"{log_entry['hour']}:{log_entry['minute']}\n" + \ f"Reason: {log_entry['reason']}\n" + \ f"Duration: {log_entry['duration']}" ), inline=False, ) await ctx.message.channel.send(embed=embed)
async def phfreeze(self, ctx): """ Lock public help system """ await ctx.message.delete() args = parse_arguments(ctx.message.content) await db.lock("public_help") phelp_data = db["public_help"]["current_channels"] if not args.check(0, re=r"(on|off)"): db.unlock("public_help") await self.tmp_msg("No matching argument passed.", ctx.message.channel) return if args[0] == "on": freeze = True elif args[0] == "off": freeze = False db["public_help"] = {"current_channels": phelp_data, "freeze": freeze} db.unlock("public_help") await self.tmp_msg("Successfully applied.", ctx.message.channel, reaction=config.REACT_SUCCESS)
async def deny(self, ctx): """ Ban users due to verification denial """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) await send_embed_dm(member, config.DENIEDMSG) await member.ban(reason="Verification denied by a moderator.") await log(ctx.message.guild, ctx.message.author, "Reject", f"rejected {member.mention}") await ctx.message.channel.send(f"Successfully denied {member.mention}!" ) # Remove data entry await db.lock("reminds") reminds = db["reminds"]["reminds"] endreminds = [] for reminder in reminds: if reminder["userid"] != member.id: endreminds.append(reminder) db["reminds"] = {"reminds": endreminds} db.unlock("reminds")
async def purge(self, ctx): """ Delete all messages of a specified user """ args = parse_arguments(ctx.message.content) # Check member = await check_for_id(ctx, args) await check_for_role(ctx, member, config.STAFFROLE, "purged") # Main logic purging_info = await ctx.send("Purging...") for channel in ctx.message.guild.channels: if channel.type == discord.ChannelType.text: await channel.purge( check=(lambda m: m.author.id == int(member.id))) await log(ctx.guild, ctx.author, "Purge", f"purged all messages from {member.mention}") await purging_info.edit( content= f"Successfully purged {member.mention}, rerun if not all messages were affected." )
async def kick(self, ctx): """ Kick a member """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) await check_for_role(ctx, member, config.STAFFROLE, "kicked") fullname = get_full_name(ctx.message.author) # Main logic if not args.check(1): await ctx.message.channel.send("Please specify a reason.") return reason = " ".join(args[1:]) await db.lock("logs") now = datetime.utcnow() logs = db["logs"]["logs"] logs.append({ "year": now.year, "month": now.month, "day": now.day, "hour": now.hour, "minute": now.minute, "userid": member.id, "guild": ctx.message.guild.id, "reason": reason, "type": "kick", }) db["logs"] = {"logs": logs} db.unlock("logs") embed = config.KICKMSG embed.add_field( name="Reason", value=reason, ) await send_embed_dm(member, embed) await log(ctx.message.guild, ctx.message.author, "Kick", f"kicked {member.mention}. Reason: {reason}") await member.kick(reason=f"Kicked by {fullname}") await ctx.message.channel.send(f"Successfully kicked {member.mention}!" )
async def phinfo(self, ctx): """ Fetch info of specific channel """ await ctx.message.delete() args = parse_arguments(ctx.message.content) phelp_data = db["public_help"]["current_channels"] table_data = {} # Check for valid request # if not args.check(0, re=r"^[0-9]*$"): await self.tmp_msg("Please supply a valid ID.", ctx.message.channel) return list_for_check = [] for data in phelp_data: list_for_check.append(str(data["channel"])) if args[0] not in list_for_check: await self.tmp_msg("Please supply a valid ID.", ctx.message.channel) return for block in phelp_data: if str(block["channel"]) == args[0]: for key, value in block.items(): if key in table_data: table_data[str(key)].append(str(value)) else: table_data[str(key)] = [str(value)] new_info_msg = await self.table(ctx.message.channel, table_data) await asyc_sleep(15) await new_info_msg.delete()
async def clearlog(self, ctx): """ Delete log of a specific user """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) await db.lock("logs") new_log = [] for log_entry in db["logs"]["logs"]: if log_entry["userid"] != int(args[0]): new_log.append(log_entry) db["logs"] = {"logs": new_log} db.unlock("logs") await ctx.message.channel.send(f"Cleared modlog of {member.mention}.")
async def verify(self, ctx): """ Remove unverified role from user and append member role TODO: Rename user role to member """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) verifiedrole = ctx.message.guild.get_role(config.VERIFIEDROLE) unverifiedrole = ctx.message.guild.get_role(config.UNVERIFIEDROLE) await member.add_roles(verifiedrole, reason="Verified by a moderator.") await member.remove_roles(unverifiedrole, reason="Verified by a moderator.") await ctx.message.channel.send( f"Successfully verified {member.mention}!") await log(ctx.message.guild, ctx.message.author, "Verification", f"verified {member.mention}") # Remove data entry await db.lock("reminds") reminds = db["reminds"]["reminds"] endreminds = [] for reminder in reminds: if reminder["userid"] != member.id: endreminds.append(reminder) db["reminds"] = {"reminds": endreminds} db.unlock("reminds")
async def whois(self, ctx): """ Whois member lookup """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) fullname = get_full_name(member) embed = discord.Embed(title=fullname, color=config.COLOR) embed.add_field( name="Nick", value=member.display_name, inline=True, ) embed.add_field( name="Username", value=fullname, inline=True, ) embed.add_field( name="Joined", value=member.joined_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False, ) embed.add_field( name="Created", value=member.created_at.strftime("%d/%m/%Y %H:%M:%S"), inline=False, ) await ctx.send(embed=embed)
password = accounts['password'] createUser(username, password) # Add wheel to sudoers addWheelToSudoers() # Enable sddm enableSddm() # Enable NetworkManager enableNetworkManager() os.system('exit') exit(0) if __name__ == "__main__": args = parse_arguments() configurationFilePath = args.file data = loadYamlFromFile(configurationFilePath) if args.ultralog: Executor.ULTRALOG = True if args.logerror: Executor.LOGERROR = True if args.chroot: chroot(data) else: archiso(data)
async def rename(self, ctx): # TODO: Rework function """ Rename an existing help channel """ args = parse_arguments(ctx.message.content) await ctx.message.delete() category = self.bot.get_channel(config.PHELPCATEGORY) await db.lock("public_help") phelp_data = db["public_help"]["current_channels"] freeze = db["public_help"]["freeze"] # Check for valid request if not args.check(0, re=r"^[0-9]*$"): await self.tmp_msg("Please supply a valid ID.", ctx.message.channel) db.unlock("public_help") return if int(args[0]) not in [data["channel"] for data in phelp_data]: await self.tmp_msg("Please supply a valid ID.", ctx.message.channel) db.unlock("public_help") return if not args.check(1): db.unlock("public_help") await self.tmp_msg("Please supply a title.", ctx.message.channel) return title = " ".join(args[1:]) if len(title) > config.PHELP_MAX_TITLE: db.unlock("public_help") await self.tmp_msg("Please supply a shorter title.", ctx) return channel_id = [ channel["channel"] for channel in phelp_data if channel["channel"] == int(args[0]) ][0] channel = self.bot.get_channel(channel_id) old_name = channel.name await channel.edit(name=title) info_msg = await ctx.message.channel.send( f"Channel successfully renamed from '{old_name}' to '{title}'.") await info_msg.add_reaction(config.REACT_SUCCESS) # Writing Data # date = datetime.utcnow() new_phelp_data = [] for data in phelp_data: if data["channel"] != int(args[0]): new_phelp_data.append(data) phelp_data.append({ "user_id": ctx.author.id, "category": category.id, "channel": channel.id, "title": title, "year": date.year, "month": date.month, "day": date.day, "hour": date.hour, "minute": date.minute, "user_name": ctx.author.name, "guild": ctx.guild.id, }) db["public_help"] = {"current_channels": phelp_data, "freeze": freeze} db.unlock("public_help") await asyc_sleep(10) await info_msg.delete()
async def fclose(self, ctx): """ Force close public help channel """ await ctx.message.delete() args = parse_arguments(ctx.message.content) await db.lock("public_help") phelp_data = db["public_help"]["current_channels"] freeze = db["public_help"]["freeze"] # Check for valid request if not args.check(0, re=r"^[0-9]*$"): db.unlock("public_help") await self.tmp_msg("Please supply a valid ID.", ctx.message.channel) return list_for_check = [] for data in phelp_data: list_for_check.append(str(data["channel"])) if args[0] not in list_for_check: db.unlock("public_help") await self.tmp_msg("Please supply a valid ID.", ctx.message.channel) return # Ask for permission # await self.request_permission(db, ctx.message.channel, ctx.message.channel, ctx.message.author, self.bot, args) # Delete Channel # end_data = [] for block in phelp_data: if str(block["channel"]) != args[0]: end_data.append(block) else: delete_channel_id = str(block["channel"]) db["public_help"] = {"current_channels": end_data, "freeze": freeze} db.unlock("public_help") delete_channel = self.bot.get_channel(int(delete_channel_id)) await delete_channel.delete(reason="Force deletion of help channel.") await self.tmp_msg("The channel has been deleted.", ctx.message.channel, reaction=config.REACT_SUCCESS)
async def unban(self, ctx): """ Unban banned user """ args = parse_arguments(ctx.message.content) if not args.check(0, re=r"^[0-9]*$"): await ctx.message.channel.send( "Please supply a valid mention or ID.") return banned_users = [ ban.user for ban in await ctx.message.guild.bans() if ban.user.id == int(args[0]) ] if len(banned_users) == 0: await ctx.message.channel.send( "Please supply a valid mention or ID.") return user = banned_users[0] fullname = get_full_name(ctx.message.author) await db.lock("punishments") punishments = db["punishments"]["punishments"] banned = False for punishment in punishments: if punishment["userid"] == user.id and \ punishment["type"] == "ban": banned = True server_banned = user.id in [ ban.user.id for ban in await ctx.message.guild.bans() ] if not banned and server_banned: db.unlock("punishments") await ctx.message.guild.unban(user, reason=f"Unbanned by {fullname}") await ctx.message.channel.send( f"Successfully unbanned {user.mention}.") return elif not banned: db.unlock("punishments") await ctx.message.channel.send( f"The user {user.mention} is not banned.") return await ctx.message.guild.unban(user, reason=f"Unmuted by {fullname}") new_punishments = [] for punishment in punishments: if punishment["userid"] != user.id or \ punishment["type"] != "ban": new_punishments.append(punishment) db["punishments"] = {"punishments": new_punishments} db.unlock("punishments") # await send_embed_dm(user, config.UNBANMSG) await log(ctx.message.guild, ctx.message.author, "Unbanned", f"unbanned {user.mention}") await ctx.message.channel.send(f"Successfully unbanned {user.mention}!" )
async def unmute(self, ctx): """ Unmute muted member """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) fullname = get_full_name(ctx.message.author) await db.lock("punishments") punishments = db["punishments"]["punishments"] muted = False for punishment in punishments: if punishment["userid"] == member.id and \ punishment["type"] == "mute": muted = True muterole = ctx.message.guild.get_role(config.MUTEDROLE) muted_role = config.MUTEDROLE in [role.id for role in member.roles] if not muted and muted_role: db.unlock("punishments") await member.remove_roles(muterole, reason="Unmuted by ") await ctx.message.channel.send( f"Successfully unmuted {member.mention}.") return elif not muted: db.unlock("punishments") await ctx.message.channel.send( f"The user {member.mention} is not muted.") return await member.remove_roles(muterole, reason=f"Unmuted by {fullname}") new_punishments = [] for punishment in punishments: if punishment["userid"] != member.id or \ punishment["type"] != "mute": new_punishments.append(punishment) db["punishments"] = {"punishments": new_punishments} db.unlock("punishments") await send_embed_dm(member, config.UNMUTEMSG) await log(ctx.message.guild, ctx.message.author, "Unmuted", f"unmuted {member.mention}") await ctx.message.channel.send( f"Successfully unmuted {member.mention}!")
async def ban(self, ctx): """ Ban user for specific time and delete messages """ args = parse_arguments(ctx.message.content) member = await check_for_id(ctx, args) await check_for_role(ctx, member, config.MODROLE, "banned") fullname = get_full_name(ctx.message.author) await db.lock("punishments") punishments = db["punishments"]["punishments"] strtotimestr = { "1d": "1 day", "2d": "2 days", "3d": "3 days", "5d": "5 days", "7d": "7 days", "14d": "14 days", "30d": "30 days", "60d": "60 days", "120d": "120 days", "240d": "240 days", "1y": "1 year", "perma": "permanently", } strtotimemin = { "1d": 1440, "2d": 2880, "3d": 4320, "5d": 7200, "7d": 10080, "14d": 20160, "30d": 43200, "60d": 86400, "120d": 172800, "240d": 345600, "1y": 525600, "perma": 999999999, } time_in_minutes, timestr = await get_punishment_reason_length( ctx, args, db, punishments, member, strtotimestr, strtotimemin, ["ban"], "ban") # Main logic reason = " ".join(args[2:]) embed = config.BANMSG embed.add_field( name="Reason", value=reason, ) embed.add_field( name="Duration", value=timestr, ) await send_embed_dm(member, embed) await log(ctx.message.guild, ctx.message.author, "Ban", f"banned {member.mention} for {timestr}. Reason: {reason}") await member.ban( reason=f"Banned by {fullname} for {timestr}. Reason: {reason}", delete_message_days=config.BANDELETEMESSAGES) # Write data endtime = datetime.utcnow() + timedelta(minutes=time_in_minutes) punishments.append({ "year": endtime.year, "month": endtime.month, "day": endtime.day, "hour": endtime.hour, "minute": endtime.minute, "userid": member.id, "guild": ctx.message.guild.id, "type": "ban", }) db["punishments"] = {"punishments": punishments} # Write log now = datetime.utcnow() db.unlock("punishments") await db.lock("logs") logs = db["logs"]["logs"] logs.append({ "year": now.year, "month": now.month, "day": now.day, "hour": now.hour, "minute": now.minute, "userid": member.id, "guild": ctx.message.guild.id, "duration": args[1], "reason": reason, "type": "ban" }) db["logs"] = {"logs": logs} db.unlock("logs") await ctx.message.channel.send(f"Successfully banned {member.mention}!" )
async def mute(self, ctx): """ Mute user for certain amount of time """ # Check stuff args = parse_arguments(ctx.message.content) # Check member = await check_for_id(ctx, args) await check_for_role(ctx, member, config.MODROLE, "muted") fullname = get_full_name(ctx.message.author) await db.lock("punishments") punishments = db["punishments"]["punishments"] strtotimestr = { "5m": "5 minutes", "30m": "30 minutes", "1h": "1 hour", "2h": "2 hours", "1d": "1 day", "2d": "2 days", "3d": "3 days", "5d": "5 days", "7d": "7 days", "perma": "permanently", } strtotimemin = { "5m": 5, "30m": 30, "1h": 60, "2h": 120, "1d": 1440, "2d": 2880, "3d": 4320, "5d": 7200, "7d": 10080, "perma": 999999999, } time_in_minutes, timestr = await get_punishment_reason_length( ctx, args, db, punishments, member, strtotimestr, strtotimemin, ["mute", "ban"], "mute") # Main logic reason = " ".join(args[2:]) embed = config.MUTEMSG embed.add_field( name="Reason", value=reason, ) embed.add_field( name="Duration", value=timestr, ) await send_embed_dm(member, embed) await log(ctx.message.guild, ctx.message.author, "Mute", f"muted {member.mention} for {timestr}. Reason: {reason}") muterole = ctx.message.guild.get_role(config.MUTEDROLE) await member.add_roles(muterole, reason=f"Muted by {fullname}") # Write data endtime = datetime.utcnow() + timedelta(minutes=time_in_minutes) punishments.append({ "year": endtime.year, "month": endtime.month, "day": endtime.day, "hour": endtime.hour, "minute": endtime.minute, "userid": member.id, "guild": ctx.message.guild.id, "type": "mute", }) db["punishments"] = {"punishments": punishments} # Write log now = datetime.utcnow() db.unlock("punishments") await db.lock("logs") logs = db["logs"]["logs"] logs.append({ "year": now.year, "month": now.month, "day": now.day, "hour": now.hour, "minute": now.minute, "userid": member.id, "guild": ctx.message.guild.id, "duration": args[1], "reason": reason, "type": "mute", }) db["logs"] = {"logs": logs} db.unlock("logs") await ctx.message.channel.send(f"Successfully muted {member.mention}!")