public async Task RemoveWarnRole(SocketRole role) { if (!((SocketGuildUser)Context.User).HasAdmin()) { await ReplyAsync("You do have administrator permissions"); return; } ModerationSettings settings = SettingFunctions.LoadModSettings(Context.Guild, true); if (settings == null) { settings = new ModerationSettings(); } if (settings.ableToWarn.Contains(role.Id)) { settings.ableToWarn.Remove(role.Id); } else { _ = ReplyAsync("People with the role \"" + role.Name + "\" can't already warn people"); } JsonSerializer serializer = new JsonSerializer(); using (StreamWriter sw = new StreamWriter(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings.txt")) using (JsonTextWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(sw, settings); } _ = ReplyAsync("People with the role \"" + role.Name + "\" can now no longer warn people"); }
public static bool CanWarn(this SocketGuildUser user) { if (HasAdmin(user)) { return(true); } ModerationSettings settings = SettingFunctions.LoadModSettings(user.Guild, false); if (settings != null && settings.ableToWarn != null && settings.ableToWarn.Count > 0) { List <SocketRole> rolesAbleToWarn = new List <SocketRole>(); foreach (ulong roleID in settings.ableToWarn) { rolesAbleToWarn.Add(user.Guild.GetRole(roleID)); } if (user.Roles.Intersect(rolesAbleToWarn).Any()) { return(true); } } foreach (SocketRole role in user.Roles) { if (role.Permissions.BanMembers) { return(true); } } return(false); }
public async Task SetLogChannel() { if (!((SocketGuildUser)Context.User).HasAdmin()) { await ReplyAsync("You do not have administrator access"); return; } IUserMessage message = await ReplyAsync("Setting..."); ModerationFunctions.CheckDirectories(Context.Guild); LogSettings settings = null; settings = SettingFunctions.LoadLogSettings(Context.Guild, true); if (Context.Client.GetChannel(settings.logChannel) == Context.Channel) { await ReplyAsync("This channel already is the logging channel"); return; } else { settings.logChannel = Context.Channel.Id; } settings.SaveLogSettings(Context.Guild); await message.ModifyAsync(msg => msg.Content = "Set log channel"); }
public async Task ToggleLoggingDeleted() { if (!Utilities.HasAdmin(Context.Message.Author as SocketGuildUser)) { await ReplyAsync("You do not have administrator access"); return; } IUserMessage message = await ReplyAsync("Setting..."); ModerationFunctions.CheckDirectories(Context.Guild); LogSettings settings = null; settings = SettingFunctions.LoadLogSettings(Context.Guild, true); settings.logDeletes = !settings.logDeletes; JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Include; settings.SaveLogSettings(Context.Guild); if (settings.logDeletes) { await message.ModifyAsync(msg => msg.Content = "Deleted messages will now be logged in the logging channel"); } else { await message.ModifyAsync(msg => msg.Content = "Deleted messages won't be logged now"); } }
public static void LogDeleted(string reason, IMessage message, SocketGuild guild = null) { try { if (deletedMessagesCache == null) { deletedMessagesCache = new List <ulong>(); } if (deletedMessagesCache.Contains(message.Id)) { return; } if (deletedMessagesCache.Count == 5) { deletedMessagesCache.RemoveAt(4); } deletedMessagesCache.Insert(0, message.Id); if (guild == null) { Utilities.GetGuild(message.Channel as SocketGuildChannel); if (guild == null) { return; } } LogSettings settings = SettingFunctions.LoadLogSettings(guild); SocketTextChannel logChannel = guild.GetChannel(settings.logChannel) as SocketTextChannel; if (settings == null || logChannel == null || !settings.logDeletes) { return; } var embed = new EmbedBuilder(); SocketTextChannel channel = message.Channel as SocketTextChannel; if (message.Embeds.Count == 0) { embed.AddField(reason + " in #" + message.Channel.Name, message.Content, true); } else { embed.AddField(reason + " in #" + channel.Name, "`Embed cannot be displayed`", true); } embed.WithFooter("ID: " + message.Id) .WithAuthor(message.Author) .WithColor(Color.Blue) .WithCurrentTimestamp(); _ = logChannel.SendMessageAsync(embed: embed.Build()); } catch (Exception exception) { Console.WriteLine(new LogMessage(LogSeverity.Error, "Logging", "Error: ", exception)); } }
public static async Task CheckMessage(SocketMessage message) { var chnl = message.Channel as SocketGuildChannel; var Guild = chnl.Guild; if (Guild != null && Directory.Exists("/home/bob_the_daniel/Data/" + Guild.OwnerId) && !Utilities.HasAdmin(message.Author as SocketGuildUser)) { JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Ignore; List <BadWord> badWords; using (StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Guild.OwnerId + "/badwords.json")) using (JsonTextReader reader = new JsonTextReader(sr)) { badWords = serializer.Deserialize <List <BadWord> >(reader); } if (message.Content.Contains("discord.gg/")) { if (!SettingFunctions.LoadModSettings(Guild).invitesAllowed) { ModerationFunctions.WarnUser(message.Author, 0.5f, "Posted Invite", Guild.OwnerId + "/Infractions/Discord/" + message.Author.Id); await message.Channel.SendMessageAsync("warned " + message.Author.Mention + " for posting a discord invite"); Logging.LogDeleted("Bad word removed", message, Guild); await message.DeleteAsync(); return; } } //Guild.OwnerId if (File.Exists("/home/bob_the_daniel/Data/" + Guild.OwnerId + "/badwords.json")) { foreach (BadWord badWord in badWords) { if (message.Content.Contains(badWord.word)) { ModerationFunctions.WarnUser(message.Author, 0.5f, "Bad word", Guild.OwnerId + "/Infractions/Discord/" + message.Author.Id); await message.Channel.SendMessageAsync("warned " + message.Author.Mention + " for bad word"); Logging.LogDeleted("Bad word removed", message, Guild); await message.DeleteAsync(); return; } } } } }
public async Task DebugLogSettings() { LogSettings settings = SettingFunctions.LoadLogSettings(Context.Guild, false); var embed = new EmbedBuilder(); SocketTextChannel logChannel = Context.Guild.GetTextChannel(settings.logChannel); if (logChannel == null) { _ = ReplyAsync("Logging channel is null"); return; } embed.AddField("Log channel", logChannel, true); embed.AddField("Log deleted messages", settings.logDeletes, true); await ReplyAsync(embed : embed.Build()); }
private static void UpdateSettingsProperty <T>(Settings.Settings settings, object propertyObject, string propertyName, T value) { Utils.SetPropertyValue(propertyObject, propertyName, value); if (Gamemode.Game.Instance.Debug) { Log.Debug($"Set {propertyName} to {value}"); } if (settings is ServerSettings serverSettings) { SettingFunctions.SendSettingsToServer(serverSettings); } else { GameEvent.Register(new Events.Settings.ChangeEvent()); } }
public async Task ModerationInfo() { ModerationSettings settings = SettingFunctions.LoadModSettings(Context.Guild, false); if (settings == null) { _ = ReplyAsync("Moderation settings are null"); return; } var embed = new EmbedBuilder(); string rolesAbleToWarn = ""; foreach (SocketRole role in Context.Guild.Roles) { if (role.Permissions.KickMembers && !role.IsManaged) { if (rolesAbleToWarn != "") { rolesAbleToWarn += "\n"; } if (role.IsMentionable) { rolesAbleToWarn += role.Mention; } else { rolesAbleToWarn += role.Name; } } } if (settings.ableToWarn != null && settings.ableToWarn.Count > 0) { foreach (ulong roleID in settings.ableToWarn) { SocketRole role = Context.Guild.GetRole(roleID); if (role != null) { if (rolesAbleToWarn != "") { rolesAbleToWarn += "\n"; } if (role.IsMentionable) { rolesAbleToWarn += role.Mention; } else { rolesAbleToWarn += role.Name; } } else { settings.ableToWarn.Remove(roleID); } } } embed.AddField("Roles that can warn", rolesAbleToWarn, true); embed.AddField("Will invites lead to warn", !settings.invitesAllowed, true); await ReplyAsync(embed : embed.Build()); }
public void GoToServerSettings() { // Call to server which sends down server data and then adds the ServerSettingsPage. SettingFunctions.RequestServerSettings(); }