public async Task SetBlackBacon(CommandContext ctx, DiscordChannel channel) { //Fetch the settings, update its prefix then save again var settings = await GuildSettings.GetGuildSettingsAsync(ctx.Guild); settings.ModLogId = (channel?.Id).GetValueOrDefault(0); await settings.SaveAsync(); //Respond that we did that. await ctx.ReplyReactionAsync(true); }
private async Task ReportModerationLogAsync(ModerationLog log, DiscordGuild guild = null, DiscordUser subject = null, DiscordUser moderator = null) { if (guild == null) { guild = await Bot.Discord.GetGuildAsync(log.GuildId); } if (moderator == null && log.ModeratorId > 0) { moderator = await Bot.Discord.GetUserAsync(log.ModeratorId); } if (subject == null && log.SubjectId > 0) { subject = await Bot.Discord.GetUserAsync(log.SubjectId); } //Figure out what hte guild modlog folder is var gs = await GuildSettings.GetGuildSettingsAsync(guild); if (gs.ModLogId > 0) { StringBuilder content = new StringBuilder(); content.AppendFormat($"**{log.Action}** | {log.Id}\n"); if (subject != null) { content.AppendLine($"**User** : {subject.Mention} ( {subject.Id} )"); } if (moderator != null) { content.AppendLine($"**Moderator** : {moderator.Mention} ( {moderator.Id} )"); } if (!string.IsNullOrWhiteSpace(log.Reason)) { content.AppendLine($"**Reason**: ```{log.Reason}```"); } //Send the message and update our log var msg = await gs.GetModLogChannel().SendMessageAsync(content.ToString()); log.Message = msg.Id; //Save the log await log.SaveAsync(DbContext); } }
public async Task SetBlackBacon(CommandContext ctx, DiscordRole role) { if (role == null) { throw new ArgumentNullException("role", "Role cannot be null!"); } //Fetch the settings, update its prefix then save again var settings = await GuildSettings.GetGuildSettingsAsync(ctx.Guild); settings.BlackBaconId = role.Id; await settings.SaveAsync(); //Respond that we did that. await ctx.ReplyReactionAsync(true); }
public async Task SetPrefix(CommandContext ctx, string prefix) { if (string.IsNullOrWhiteSpace(prefix)) { throw new ArgumentNullException("prefix", "Prefix cannot be null or empty."); } //Fetch the settings, update its prefix then save again var settings = await GuildSettings.GetGuildSettingsAsync(ctx.Guild); settings.Prefix = prefix; await settings.SaveAsync(); //Respond that we did that. await ctx.ReplyReactionAsync(true); }
/// <summary> /// Removes the black bacon role to a user. /// </summary> /// <param name="member"></param> /// <param name="moderator"></param> /// <param name="reason"></param> /// <returns></returns> public async Task <bool> RemoveBlackBaconAsync(DiscordMember member, DiscordMember moderator = null) { //Get the guild settings, and make sure they are valid var settings = await GuildSettings.GetGuildSettingsAsync(member.Guild); if (settings.GuildId < 0) { throw new Exception("Black Bacon role not yet defined."); } var bbrole = settings.GetBlackBaconRole(); if (bbrole == null) { throw new Exception("Black Bacon role not yet defined or has since been deleted."); } //Get all the roles and clear out the store var rStoreKey = Namespace.Combine(member.Guild, member, "bbroles"); var rStore = await Bot.Redis.FetchHashSetAsync(rStoreKey); await Bot.Redis.RemoveAsync(rStoreKey); if (rStore == null) { return(false); } //Prepare the roles var roles = rStore .Select(str => ulong.TryParse(str, out var id) ? id : 0) .Select(id => member.Guild.GetRole(id)) .Where(role => role != null); //Award the roles await member.ReplaceRolesAsync(roles, member.Username + " removed BB"); await Bot.ModerationManager.RecordModerationAsync("blackbacon", moderator, member, "Black Bacon Removed"); return(true); }
/// <summary> /// Applies the black bacon role to a user. /// </summary> /// <param name="member"></param> /// <param name="moderator"></param> /// <param name="reason"></param> /// <returns></returns> public async Task GiveBlackBaconAsync(DiscordMember member, DiscordMember moderator = null, string reason = null) { //Get the guild settings, and make sure they are valid var settings = await GuildSettings.GetGuildSettingsAsync(member.Guild); if (settings.GuildId < 0) { throw new Exception("Black Bacon role not yet defined."); } var bbrole = settings.GetBlackBaconRole(); if (bbrole == null) { throw new Exception("Black Bacon role not yet defined or has since been deleted."); } //Get the keys var rStoreKey = Namespace.Combine(member.Guild, member, "bbroles"); if (await Redis.ExistsAsync(rStoreKey)) { throw new Exception("The user has already been black baconed."); } //Calculate what roles we should add to the list var rStore = member.Roles .Prepend(member.Guild.EveryoneRole) .Where(r => r.Id != bbrole.Id) .Select(r => r.Id.ToString()) .ToHashSet(); //Add the hash, apply the roles and update their sync await Bot.Redis.AddHashSetAsync(rStoreKey, rStore); await member.ReplaceRolesAsync(new DiscordRole[] { bbrole }); await Bot.ModerationManager.RecordModerationAsync("blackbacon", moderator, member, reason); }
public async Task UnblackBacon(CommandContext ctx, [Description("The member to unblack bacon.")] DiscordMember member) { if (member == null) { throw new ArgumentNullException("member"); } if (member == ctx.Member) { throw new ArgumentException("Cannot be yourself", "member"); } var settings = await GuildSettings.GetGuildSettingsAsync(ctx.Guild); if (settings.GuildId < 0) { throw new Exception("Black Bacon role not yet defined."); } var success = await Manager.RemoveBlackBaconAsync(member, ctx.Member); await ctx.ReplyReactionAsync(success); }