public RegisteredCommand(string prefix, DiscordPermissionLevel level, CommandCallback callback, string info) { this.prefix = prefix; this.requiredLevel = level; this.callback = callback; this.info = info; }
public static async Task OnCommand(DSharpPlus.EventArgs.MessageCreateEventArgs e, string prefix, string content) { //Get Discord member and user data DiscordMember member = await e.Guild.GetMemberAsync(e.Author.Id); DiscordUserData data = BotTools.GetUserDataById(e.Author.Id); data.latest_name = $"{e.Author.Username}#{e.Author.Discriminator}"; //Identify the permission level of this member DiscordPermissionLevel perms = DiscordPermissionLevel.Default; if (member.Roles.Where(x => x.Id == Program.config.muted_role).Count() > 0) { perms = DiscordPermissionLevel.Moderator; } if (member.Roles.Where(x => x.Id == Program.config.admin_role).Count() > 0) { perms = DiscordPermissionLevel.Admin; } //Now, find a command we can use. foreach (var c in commands) { if (c.prefix.ToLower() != prefix.ToLower()) { continue; } if (c.requiredLevel > perms) { //Tell the user that they're not allowed to do that. await OnCommandAuthFailed(e, c); return; } try { await c.callback(e, prefix, content, member, perms, data); } catch (Exception ex) { //Failed! Program.LogMessage("cmd-error", ex.Message + ex.StackTrace); await OnCommandExceptionFailed(e, c, ex); } } }
public static async Task OnCmd(DSharpPlus.EventArgs.MessageCreateEventArgs e, string prefix, string content, DiscordMember member, DiscordPermissionLevel perms, DiscordUserData data) { //Check if this is prompting for help string[] split = content.Split(','); if (content.Length == 0 || split.Length < 3) { await ReturnHelp(e); return; } //Parse the message parts string memberString = split[0]; string timeString = split[1]; string messageString = content.Substring(2 + memberString.Length + timeString.Length); //Find the user DiscordUser victim = await BotTools.ParseName(e.Guild, memberString.Trim(' ')); //If the bot failed to find the user, throw an error if (victim == null) { await ReturnError(e, "Failed to Find User", $"Failed to find the user, ``{memberString.Trim(' ')}``. You can use their ID, their full name, or their first name. You can also mention them."); return; } //Find time DateTime time; int timeParseErrorCount = 0; int timeParseCount = 0; if (timeString.Trim(' ').ToLower() != "never") { time = BotTools.ParseTime(timeString.Trim(' '), out timeParseErrorCount, out timeParseCount); } else { await ReturnError(e, "Cannot Perma Ban", "Please use the ban function built into Discord to permaban a member."); return; } //If the time parse didn't find any, or if there were any errors, stop if ((timeParseCount == 0 || timeParseErrorCount > 0)) { await ReturnError(e, "Failed to Parse Time", "There was a problem parsing the time you entered. Do not include commas in the time, make sure you use spaces to separate each part, and make sure you do not use weeks. For help, do not include any arguments and run the command again."); return; } //Limit message to 900 characters if (messageString.Length > 900) { await ReturnError(e, "Reason is Too Long", "Sorry, the reason is limited by Discord to 900 characters."); return; } //Get the user data for the person we just banned and apply. DiscordUserData victimUserData = BotTools.GetUserDataById(victim.Id); victimUserData.latest_name = $"{victim.Username}#{victim.Discriminator}"; victimUserData.temp_banned = new DiscordUserDataStatusBanned { applied_since = DateTime.UtcNow.Ticks, catalyst = e.Author.Id, expiry = time.Ticks, is_applied = true, is_automated = false, reason = messageString }; //Apply the ban to the account await ActionTools.BanTools.DoBanMember(victimUserData, e.Guild, victim, e.Author, messageString, false, time); //Save victimUserData.Save(); //Write OK await ReturnOk(e, victim, time); }
public static async Task OnCmd(DSharpPlus.EventArgs.MessageCreateEventArgs e, string prefix, string content, DiscordMember member, DiscordPermissionLevel perms, DiscordUserData data) { //Check if this is prompting for help string[] split = content.Split(','); if (content.Length == 0 || split.Length < 3) { await ReturnHelp(e); return; } //Parse the message parts string memberString = split[0]; string timeString = split[1]; string messageString = content.Substring(2 + memberString.Length + timeString.Length); //Find the user DiscordUser victim = await BotTools.ParseName(e.Guild, memberString.Trim(' ')); //If the bot failed to find the user, throw an error if (victim == null) { await ReturnError(e, "Failed to Find User", $"Failed to find the user, ``{memberString.Trim(' ')}``. You can use their ID, their full name, or their first name. You can also mention them."); return; } //Find time bool isForever = true; DateTime?time; int timeParseErrorCount = 0; int timeParseCount = 0; if (timeString.Trim(' ').ToLower() != "never") { time = BotTools.ParseTime(timeString.Trim(' '), out timeParseErrorCount, out timeParseCount); isForever = false; } else { time = null; } //If the time parse didn't find any, or if there were any errors, stop if (time != null && (timeParseCount == 0 || timeParseErrorCount > 0)) { await ReturnError(e, "Failed to Parse Time", "There was a problem parsing the time you entered. Do not include commas in the time, make sure you use spaces to separate each part, and make sure you do not use weeks. For help, do not include any arguments and run the command again."); return; } //Limit message to 900 characters if (messageString.Length > 900) { await ReturnError(e, "Reason is Too Long", "Sorry, the reason is limited by Discord to 900 characters."); return; } //Awesome. Now, create the strike DiscordUserDataStrike strike = new DiscordUserDataStrike { time = DateTime.UtcNow.Ticks, striker = e.Author.Id, message = messageString }; if (time.HasValue) { strike.expire_time = time.Value.Ticks; } //Get the user data for the person we just struck and apply. DiscordUserData victimUserData = BotTools.GetUserDataById(victim.Id); victimUserData.strikes.Add(strike); //Send a notification of this to the person await NotifyStrike(victim, member, strike, e.Guild, victimUserData); //Check if we need to issue a ban for this member var activeStrikes = victimUserData.GetActiveStrikes(); if (activeStrikes.Length >= Program.config.ban_strikes) { //Ban time! Find when the latest ban expire happens DateTime latest_expire = DateTime.MaxValue; bool does_expire = false; foreach (var a in activeStrikes) { if (a.expire_time.HasValue) { does_expire = true; if (a.GetExpiry().Value < latest_expire) { latest_expire = a.GetExpiry().Value; } } } if (does_expire) { //Temp ban await ActionTools.BanTools.DoBanMember(victimUserData, e.Guild, victim, e.Author, "You are banned for having too many strikes.", true, latest_expire); } else { //Send message await ActionTools.BanTools.NotifyPermaBan(e.Guild, victim, e.Author, "You are banned for having too many strikes.", true); //Ban from the server DiscordMember victimMember = await e.Guild.GetMemberAsync(victim.Id); await e.Guild.BanMemberAsync(victimMember, 0, "Temporary ban system."); } } //Save victimUserData.Save(); //Return OK await ReturnOk(e, victim, activeStrikes.Length); }
public static async Task OnCmd(DSharpPlus.EventArgs.MessageCreateEventArgs e, string prefix, string content, DiscordMember member, DiscordPermissionLevel perms, DiscordUserData data) { //Create an embed with all of the commands this user has access to var cmds = CommandProcessor.commands.Where(x => x.requiredLevel <= perms); DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); builder.Title = "Command Help"; builder.Description = "With any command, run it without any parameters for help."; builder.Color = DiscordColor.Grayple; builder.Footer = new DiscordEmbedBuilder.EmbedFooter { Text = Program.FOOTER_TEXT }; foreach (var c in cmds) { builder.AddField(Program.config.command_prefix + c.prefix, c.info, true); } await e.Message.RespondAsync(embed : builder.Build()); }
public static async Task OnCmd(DSharpPlus.EventArgs.MessageCreateEventArgs e, string prefix, string content, DiscordMember member, DiscordPermissionLevel perms, DiscordUserData data) { if (content.Length == 0) { await ReturnHelp(e); return; } //Do it //Find the user DiscordUser victim = await BotTools.ParseOfflineName(content.Trim(' ')); //If not found, complain if (victim == null) { DiscordEmbedBuilder badBuilder = new DiscordEmbedBuilder(); badBuilder.Title = "User Not Found"; badBuilder.Description = $"\"{content.Trim(' ')}\" was not found. Try their ID."; badBuilder.Color = DiscordColor.Yellow; badBuilder.Footer = new DiscordEmbedBuilder.EmbedFooter { Text = Program.FOOTER_TEXT }; await e.Message.RespondAsync(embed : badBuilder.Build()); return; } //Get user DiscordUserData victimData = BotTools.GetUserDataById(victim.Id); //Set as not active victimData.temp_banned.is_applied = false; //Save victimData.Save(); //Write OK DiscordEmbedBuilder okBuilder = new DiscordEmbedBuilder(); okBuilder.Title = "User Unbanned"; okBuilder.Description = $"{victim.Username}#{victim.Discriminator} ({victim.Id}) was unbanned."; okBuilder.Color = DiscordColor.Green; okBuilder.Footer = new DiscordEmbedBuilder.EmbedFooter { Text = Program.FOOTER_TEXT }; await e.Message.RespondAsync(embed : okBuilder.Build()); }