public async Task ModRoles() { var guild = GuildRepository.FetchGuild(Context.Guild.Id); if (guild.ModRoles == null) { throw new Exception("There are no moderator roles yet!"); } var description = ""; foreach (var modRole in guild.ModRoles.OrderBy(x => x.Value)) { var role = Context.Guild.GetRole(Convert.ToUInt64(modRole.Name)); if (role == null) { guild.ModRoles.Remove(modRole.Name); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, guild.ModRoles), Context.Guild.Id); continue; } description += $"{role.Mention}: Pemission level {modRole.Value}"; } if (description.Length > 2048) { throw new Exception("You have too many mod roles to be able to use this command."); } var builder = new EmbedBuilder() { Title = "Moderator Roles", Color = new Color(0x00AE86), Description = description }; await ReplyAsync("", embed : builder); }
public async Task Ranks() { var guild = GuildRepository.FetchGuild(Context.Guild.Id); if (guild.RankRoles == null) { throw new Exception("There are no ranks yet!"); } var description = ""; foreach (var rank in guild.RankRoles.OrderBy(x => x.Value)) { var role = Context.Guild.GetRole(Convert.ToUInt64(rank.Name)); if (role == null) { guild.RankRoles.Remove(rank.Name); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id); continue; } description += $"{rank.Value.AsDouble.ToString("C", Config.CI)}: {role.Mention}\n"; } if (description.Length > 2048) { throw new Exception("You have too many ranks to be able to use this command."); } var builder = new EmbedBuilder() { Title = "Ranks", Color = new Color(0x00AE86), Description = description }; await ReplyAsync("", embed : builder); }
public async Task AddRank(IRole rankRole, double cashRequired) { var guild = GuildRepository.FetchGuild(Context.Guild.Id); if (rankRole.Position >= Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position) { throw new Exception($"DEA must be higher in the heigharhy than {rankRole.Mention}."); } if (guild.RankRoles == null) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, new BsonDocument() { { rankRole.Id.ToString(), cashRequired } }), Context.Guild.Id); } else { if (guild.RankRoles.Any(x => x.Name == rankRole.Id.ToString())) { throw new Exception("This role is already a rank role."); } if (guild.RankRoles.Any(x => (int)x.Value.AsDouble == (int)cashRequired)) { throw new Exception("There is already a role set to that amount of cash required."); } guild.RankRoles.Add(rankRole.Id.ToString(), cashRequired); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id); } await ReplyAsync($"You have successfully added the {rankRole.Mention} rank!"); }
public static async Task ModLog(SocketCommandContext context, string action, Color color, string reason, IUser subject = null, string extra = "") { var guild = GuildRepository.FetchGuild(context.Guild.Id); EmbedFooterBuilder footer = new EmbedFooterBuilder() { IconUrl = "http://i.imgur.com/BQZJAqT.png", Text = $"Case #{guild.CaseNumber}" }; EmbedAuthorBuilder author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl(), Name = $"{context.User.Username}#{context.User.Discriminator}" }; string userText = null; if (subject != null) { userText = $"\n** User:** { subject} ({ subject.Id})"; } var builder = new EmbedBuilder() { Author = author, Color = color, Description = $"**Action:** {action}{extra}{userText}\n**Reason:** {reason}", Footer = footer }.WithCurrentTimestamp(); if (context.Guild.GetTextChannel(guild.ModLogId) != null) { await context.Guild.GetTextChannel(guild.ModLogId).SendMessageAsync("", embed: builder); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.CaseNumber, ++guild.CaseNumber), context.Guild.Id); } }
public async Task SetPrefix(string prefix) { if (prefix.Length > 3) { throw new Exception("The maximum character length of a prefix is 3."); } GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.Prefix, prefix), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully set the prefix to {prefix}!"); }
public async Task SetMutedRole(IRole mutedRole) { if (mutedRole.Position >= Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position) { throw new Exception($"DEA must be higher in the heigharhy than {mutedRole.Mention}."); } GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.MutedRoleId, mutedRole.Id), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully set the muted role to {mutedRole.Mention}!"); }
public async Task SetNSFWChannel(ITextChannel nsfwChannel) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.NsfwId, nsfwChannel.Id), Context.Guild.Id); var nsfwRole = Context.Guild.GetRole(GuildRepository.FetchGuild(Context.Guild.Id).NsfwRoleId); if (nsfwRole != null && Context.Guild.CurrentUser.GuildPermissions.Administrator) { await nsfwChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new OverwritePermissions().Modify(null, null, null, PermValue.Deny)); await nsfwChannel.AddPermissionOverwriteAsync(nsfwRole, new OverwritePermissions().Modify(null, null, null, PermValue.Allow)); } await ReplyAsync($"{Context.User.Mention}, You have successfully set the NSFW channel to {nsfwChannel.Mention}."); }
public async Task RemoveModRole(IRole modRole) { var guild = GuildRepository.FetchGuild(Context.Guild.Id); if (guild.ModRoles == null) { throw new Exception("There are no moderator roles yet!"); } if (!guild.ModRoles.Any(x => x.Name == modRole.Id.ToString())) { throw new Exception("This role is not a moderator role!"); } guild.ModRoles.Remove(modRole.Id.ToString()); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, guild.ModRoles), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully set the moderator role to {modRole.Mention}!"); }
public async Task RemoveRank(IRole rankRole) { var guild = GuildRepository.FetchGuild(Context.Guild.Id); if (guild.RankRoles == null) { throw new Exception("There are no ranks yet!"); } if (!guild.RankRoles.Any(x => x.Name == rankRole.Id.ToString())) { throw new Exception("This role is not a rank role."); } guild.RankRoles.Remove(rankRole.Id.ToString()); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id); await ReplyAsync($"You have successfully removed the {rankRole.Mention} rank!"); }
public async Task ChangeNSFWSettings() { switch (GuildRepository.FetchGuild(Context.Guild.Id).Nsfw) { case true: GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.Nsfw, false), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully disabled NSFW commands!"); break; case false: GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.Nsfw, true), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully enabled NSFW commands!"); break; } }
public async Task SetNSFWRole(IRole nsfwRole) { if (nsfwRole.Position > Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position) { throw new Exception("You may not set the NSFW role to a role that is higher in hierarchy than DEA's highest role."); } GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.NsfwRoleId, nsfwRole.Id), Context.Guild.Id); var nsfwChannel = Context.Guild.GetChannel(GuildRepository.FetchGuild(Context.Guild.Id).NsfwId); if (nsfwChannel != null && Context.Guild.CurrentUser.GuildPermissions.Administrator) { await nsfwChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new OverwritePermissions().Modify(null, null, null, PermValue.Deny)); await nsfwChannel.AddPermissionOverwriteAsync(nsfwRole, new OverwritePermissions().Modify(null, null, null, PermValue.Allow)); } await ReplyAsync($"{Context.User.Mention}, You have successfully set the NSFW role to {nsfwRole.Mention}."); }
private void AutoUnmute() { Timer t = new Timer(async method => { foreach (Mute mute in await(await DEABot.Mutes.FindAsync("")).ToListAsync()) { if (DateTime.UtcNow.Subtract(mute.MutedAt).TotalMilliseconds > mute.MuteLength) { var guild = _client.GetGuild(mute.GuildId); if (guild != null && guild.GetUser(mute.UserId) != null) { var guildData = GuildRepository.FetchGuild(guild.Id); var mutedRole = guild.GetRole(guildData.MutedRoleId); if (mutedRole != null && guild.GetUser(mute.UserId).Roles.Any(x => x.Id == mutedRole.Id)) { var channel = guild.GetTextChannel(guildData.ModLogId); if (channel != null && guild.CurrentUser.GuildPermissions.EmbedLinks && (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).SendMessages && (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).EmbedLinks) { await guild.GetUser(mute.UserId).RemoveRoleAsync(mutedRole); var footer = new EmbedFooterBuilder() { IconUrl = "http://i.imgur.com/BQZJAqT.png", Text = $"Case #{guildData.CaseNumber}" }; var builder = new EmbedBuilder() { Color = new Color(12, 255, 129), Description = $"**Action:** Automatic Unmute\n**User:** {guild.GetUser(mute.UserId)} ({guild.GetUser(mute.UserId).Id})", Footer = footer }.WithCurrentTimestamp(); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.CaseNumber, ++guildData.CaseNumber), guild.Id); await channel.SendMessageAsync("", embed: builder); } } } MuteRepository.RemoveMute(mute.UserId, mute.GuildId); } } }, null, Config.AUTO_UNMUTE_COOLDOWN, Timeout.Infinite); }
public static async Task DetailedLog(SocketGuild guild, string actionType, string action, string objectType, string objectName, ulong id, Color color, bool incrementCaseNumber = true) { var guildData = GuildRepository.FetchGuild(guild.Id); if (guild.GetTextChannel(guildData.DetailedLogsId) != null) { var channel = guild.GetTextChannel(guildData.DetailedLogsId); if (guild.CurrentUser.GuildPermissions.EmbedLinks && (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).SendMessages && (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).EmbedLinks) { string caseText = $"Case #{guildData.CaseNumber}"; if (!incrementCaseNumber) { caseText = id.ToString(); } EmbedFooterBuilder footer = new EmbedFooterBuilder() { IconUrl = "http://i.imgur.com/BQZJAqT.png", Text = caseText }; string idText = null; if (incrementCaseNumber) { idText = $"\n**Id:** {id}"; } var builder = new EmbedBuilder() { Color = color, Description = $"**{actionType}:** {action}\n**{objectType}:** {objectName}{idText}", Footer = footer }.WithCurrentTimestamp(); await guild.GetTextChannel(guildData.DetailedLogsId).SendMessageAsync("", embed: builder); if (incrementCaseNumber) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.CaseNumber, ++guildData.CaseNumber), guild.Id); } } } }
public async Task AddModRole(IRole modRole, int permissionLevel = 1) { if (permissionLevel < 1 || permissionLevel > 3) { throw new Exception("Permission levels:\nModeration: 1\nAdministration: 2\nServer Owner: 3"); } var guild = GuildRepository.FetchGuild(Context.Guild.Id); if (guild.ModRoles == null) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, new BsonDocument() { { modRole.Id.ToString(), permissionLevel } }), Context.Guild.Id); } else { guild.ModRoles.Add(modRole.Id.ToString(), permissionLevel); GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, guild.ModRoles), Context.Guild.Id); } await ReplyAsync($"{Context.User.Mention}, You have successfully add {modRole.Mention} as a Moderation role with a permission level of {permissionLevel}."); }
public async Task SetGambleChannel(ITextChannel gambleChannel) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.GambleId, gambleChannel.Id), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully set the gamble channel to {gambleChannel.Mention}!"); }
public async Task SetModLogChannel(ITextChannel modLogChannel) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModLogId, modLogChannel.Id), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully set the moderator log channel to {modLogChannel.Mention}!"); }
public async Task SetDetailedLogsChannel(ITextChannel detailedLogsChannel) { GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.DetailedLogsId, detailedLogsChannel.Id), Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully set the detailed logs channel to {detailedLogsChannel.Mention}!"); }