public async Task MuteUser(SocketGuildUser user, TimeSpan?time = null, [Remainder] string reason = null) { if (!await IsActionable(user, Context.User as SocketGuildUser)) { return; } //Log this to some config file? var config = ModHandler.GetActionConfig(Context.Guild.Id); var muteRole = await ModHandler.GetOrCreateMuteRole(config, Context.Guild); await user.AddRoleAsync(muteRole); if (time == null) { time = config.MuteLength; } ModHandler.TimedActions.Users.Add(new Models.TimeTracker.User(user.Id, Context.Guild.Id, Models.TimeTracker.User.TimedAction.Mute, time.Value)); var caseId = config.AddLogAction(user.Id, Context.User.Id, ActionConfig.Log.LogAction.Mute, reason); ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); ModHandler.Save(ModHandler.TimedActions, TimeTracker.DocumentName); var expiryTime = DateTime.UtcNow + time.Value; await ReplyAsync($"#{caseId} {user.Mention} has been muted for {time.Value.GetReadableLength()}, Expires at: {expiryTime.ToShortDateString()} {expiryTime.ToShortTimeString()}\n**Reason:** {reason ?? "N/A"}"); await ModHandler.LogMessageAsync(Context, $"#{caseId} {user.Mention} has been muted for {time.Value.GetReadableLength()}, Expires at: {expiryTime.ToShortDateString()} {expiryTime.ToShortTimeString()}", user, reason); }
public async Task SoftBanUser(SocketGuildUser user, TimeSpan?time = null, [Remainder] string reason = null) { if (!await IsActionable(user, Context.User as SocketGuildUser)) { return; } var config = ModHandler.GetActionConfig(Context.Guild.Id); if (time == null) { time = config.SoftBanLength; } var expiryTime = DateTime.UtcNow + time.Value; await ReplyAsync($"You have been SoftBanned in {Context.Guild.Name} for {time.Value.GetReadableLength()}, Expires at: {expiryTime.ToShortDateString()} {expiryTime.ToShortTimeString()} \n**Reason:** {reason ?? "N/A"}"); await Context.Guild.AddBanAsync(user, 0, reason); ModHandler.TimedActions.Users.Add(new Models.TimeTracker.User(user.Id, Context.Guild.Id, Models.TimeTracker.User.TimedAction.SoftBan, time.Value)); ModHandler.Save(ModHandler.TimedActions, TimeTracker.DocumentName); var caseId = config.AddLogAction(user.Id, Context.User.Id, ActionConfig.Log.LogAction.SoftBan, reason); ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ReplyAsync($"#{caseId} {user.Mention} has been SoftBanned for {time.Value.GetReadableLength()}, Expires at: {expiryTime.ToShortDateString()} {expiryTime.ToShortTimeString()} \n**Reason:** {reason ?? "N/A"}"); await ModHandler.LogMessageAsync(Context, $"#{caseId} {user.Mention} has been SoftBanned for {time.Value.GetReadableLength()}, Expires at: {expiryTime.ToShortDateString()} {expiryTime.ToShortTimeString()}", user, reason); }
public async Task SetReason(int caseId, [Remainder] string reason) { var config = ModHandler.GetActionConfig(Context.Guild.Id); var action = config.LogActions.FirstOrDefault(x => x.CaseId == caseId); if (action == null) { await ReplyAsync("Invalid Case ID"); return; } //Check if reason is updated or list needs to be re-updated if (action.Reason == null || action.Reason.Equals("N/A")) { action.Reason = reason; await ReplyAsync("Reason set."); await ModHandler.LogMessageAsync(Context, $"#{caseId} reason was set", null, reason); } else { action.Reason = $"**Original Reason**\n{action.Reason}**Updated Reason**\n{reason}"; await ReplyAsync("Appended reason to message."); //TODO: Get user if possible. await ModHandler.LogMessageAsync(Context, $"#{caseId} reason was updated", null, reason); } ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); }
public async Task HackBanAsync(ulong userId, [Remainder] string reason = null) { var gUser = Context.Guild.GetUser(userId); if (gUser != null) { if (!await IsActionable(gUser, Context.User as SocketGuildUser)) { return; } } var config = ModHandler.GetActionConfig(Context.Guild.Id); var caseId = config.AddLogAction(userId, Context.User.Id, ActionConfig.Log.LogAction.Ban, reason); ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await Context.Guild.AddBanAsync(userId, 0, reason); await ReplyAsync($"#{caseId} Hackbanned user with ID {userId}"); if (gUser != null) { await ModHandler.LogMessageAsync(Context, $"#{caseId} Hackbanned user with ID {userId}", gUser, reason); } else { await ModHandler.LogMessageAsync(Context, $"#{caseId} Hackbanned user with ID {userId}", userId, reason); } }
public async Task SetLogChannelAsync() { var config = ModHandler.GetActionConfig(Context.Guild.Id); config.LogChannelId = Context.Channel.Id; ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ReplyAsync($"Log channel set to the current channel."); }
public async Task DefaultMuteTime(TimeSpan time) { var config = ModHandler.GetActionConfig(Context.Guild.Id); config.MuteLength = time; ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ReplyAsync($"By Default users will be muted for {time.GetReadableLength()}"); }
public async Task MaxWarningsAction(ActionConfig.Action action) { var config = ModHandler.GetActionConfig(Context.Guild.Id); config.MaxWarningsAction = action; ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ReplyAsync($"Max Warnings Action is now: {action}"); }
public async Task MaxWarnings(int max) { var config = ModHandler.GetActionConfig(Context.Guild.Id); config.MaxWarnings = max; ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ReplyAsync($"Max Warnings is now: {max}"); }
public ActionConfig GetActionConfig(ulong guildId) { var config = Database.Load <ActionConfig>(ActionConfig.DocumentName(guildId)); if (config == null) { config = new ActionConfig(guildId); Database.Store(config, ActionConfig.DocumentName(guildId)); } return(config); }
public async Task WarnUser(SocketGuildUser user, [Remainder] string reason = null) { if (!await IsActionable(user, Context.User as SocketGuildUser)) { return; } //Log this to some config file? var config = ModHandler.GetActionConfig(Context.Guild.Id); var userConfig = ModHandler.GetActionUser(Context.Guild.Id, user.Id); var warns = userConfig.WarnUser(Context.User.Id, reason); var caseId = config.AddLogAction(user.Id, Context.User.Id, ActionConfig.Log.LogAction.Warn, reason); ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); ModHandler.Save(userConfig, ActionConfig.ActionUser.DocumentName(user.Id, Context.Guild.Id)); await ReplyAsync($"#{caseId} {user.Mention} was warned by {Context.User.Mention} for {reason ?? "N/A"}"); await ModHandler.LogMessageAsync(Context, $"#{caseId} {user.Mention} was warned by {Context.User.Mention}", user, reason); //TODO: Separate actions for below. if (warns > config.MaxWarnings) { if (config.MaxWarningsAction == Models.ActionConfig.Action.Kick) { await user.KickAsync("Exceeded maimum warnings."); await ReplyAsync($"{user.Mention} was kicked for exceeding the max warning count"); } else if (config.MaxWarningsAction == Models.ActionConfig.Action.Ban) { await Context.Guild.AddBanAsync(user, 0, "Exceeded maximum warnings."); await ReplyAsync($"{user.Mention} was banned for exceeding the max warning count"); } else if (config.MaxWarningsAction == Models.ActionConfig.Action.SoftBan) { await SoftBanUser(user, "Exceeded maximum warnings."); await ReplyAsync($"{user.Mention} was soft-banned for `{config.SoftBanLength.GetReadableLength()}` for exceeding the max warning count"); } else if (config.MaxWarningsAction == Models.ActionConfig.Action.Mute) { await MuteUser(user, "Exceeded maximum warnings"); await ReplyAsync($"{user.Mention} was muted for `{config.SoftBanLength.GetReadableLength()}` for exceeding the max warning count"); } } }
public async Task KickUser(SocketGuildUser user, [Remainder] string reason = null) { if (!await IsActionable(user, Context.User as SocketGuildUser)) { return; } await user.KickAsync(reason); var config = ModHandler.GetActionConfig(Context.Guild.Id); var caseId = config.AddLogAction(user.Id, Context.User.Id, ActionConfig.Log.LogAction.Kick, reason); await ReplyAsync($"#{caseId} {user.Mention} was kicked by {Context.User.Mention} for {reason ?? "N/A"}"); ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ModHandler.LogMessageAsync(Context, $"#{caseId} {user.Mention} was kicked by {Context.User.Mention}", user, reason); }
/// <summary> /// Tries to get the mute role, if unsuccessful creats a new one. /// Will automatically apply relevant permissions for all channels in the guild /// </summary> /// <param name="config"></param> /// <param name="guild"></param> /// <returns></returns> public async Task <IRole> GetOrCreateMuteRole(ActionConfig config, SocketGuild guild) { IRole role; if (config.MuteRole == 0) { //If the role isn't set just create it role = await guild.CreateRoleAsync("Muted"); config.MuteRole = role.Id; Save(config, ActionConfig.DocumentName(guild.Id)); } else { role = guild.GetRole(config.MuteRole); if (role == null) { //In the case that the role was removed or is otherwise unavailable generate a new one role = await guild.CreateRoleAsync("Muted"); config.MuteRole = role.Id; Save(config, ActionConfig.DocumentName(guild.Id)); } //Set the default role permissions to deny the only ways the user can communicate in the server if (role.Permissions.SendMessages || role.Permissions.AddReactions || role.Permissions.Connect || role.Permissions.Speak) { await role.ModifyAsync(x => { x.Permissions = new GuildPermissions(sendMessages: false, addReactions: false, connect: false, speak: false); }); } } foreach (var channel in guild.Channels) { //Update channel permission overwrites to stop the user from being able to communicate if (channel.PermissionOverwrites.All(x => x.TargetId != role.Id)) { var _ = Task.Run(async() => await channel.AddPermissionOverwriteAsync(role, new OverwritePermissions(sendMessages: PermValue.Deny, addReactions: PermValue.Deny, connect: PermValue.Deny, speak: PermValue.Deny))); } } return(role); }
public async Task BanUser(SocketGuildUser user, [Remainder] string reason = null) { if (!await IsActionable(user, Context.User as SocketGuildUser)) { return; } //Setting for prune days is needed //Log this to some config file? await user.Guild.AddBanAsync(user, 0, reason); var config = ModHandler.GetActionConfig(Context.Guild.Id); var caseId = config.AddLogAction(user.Id, Context.User.Id, ActionConfig.Log.LogAction.Ban, reason); await ReplyAsync($"#{caseId} {user.Mention} was banned by {Context.User.Mention} for {reason ?? "N/A"}"); ModHandler.Save(config, ActionConfig.DocumentName(Context.Guild.Id)); await ModHandler.LogMessageAsync(Context, $"#{caseId} {user.Mention} was banned by {Context.User.Mention} for {reason ?? "N/A"}", user, reason); }