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 async Task RemooveWarnAsync(SocketUser user, int index) { ModerationFunctions.CheckDirectories(Context.Guild); if (File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id)) { List <Infraction> infractions = ModerationFunctions.LoadInfractions(Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id); if (infractions.Count < index || index <= 0) { await ReplyAsync("invalid infraction number"); } else if (infractions.Count == 1) { await ReplyAsync("removed " + user.Username + "'s warning for " + infractions[index - 1].reason); File.Delete("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id); } else { string reason = infractions[index - 1].reason; infractions.RemoveAt(index - 1); ModerationFunctions.SaveInfractions(Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id, infractions); await ReplyAsync("removed " + user.Mention + "'s warning for " + reason); } } else { await ReplyAsync(user.Username + " has no warns"); } }
public async Task WarnUserSmallSizeAsync(SocketUser user, [Remainder] string reason) { ModerationFunctions.CheckDirectories(Context.Guild); ModerationFunctions.WarnUser(user, 1, reason, Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id); await ReplyAsync(user.Username + " has been warned for " + reason); }
public async Task ToggleInviteWarn() { if (!((SocketGuildUser)Context.User).HasAdmin()) { await ReplyAsync("You do have administrator permissions"); return; } Console.WriteLine(DateTime.Now.ToShortTimeString() + " Toggling invite warn"); IUserMessage message = await ReplyAsync("Trying to toggle"); ModerationFunctions.CheckDirectories(Context.Guild); ModerationSettings settings = null; JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Include; try { StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings.txt"); JsonTextReader reader = new JsonTextReader(sr); settings = serializer.Deserialize <ModerationSettings>(reader); } catch (Exception error) { await message.ModifyAsync(msg => msg.Content = "an error has occurred loading settings " + error.Message); Console.WriteLine(DateTime.Now.ToShortTimeString() + "an error has occurred loading settings " + error.Message); } if (settings == null) { settings = new ModerationSettings(); Console.WriteLine(DateTime.Now.ToShortTimeString() + " Creating new mod settings"); } settings.invitesAllowed = !settings.invitesAllowed; Console.WriteLine(DateTime.Now.ToShortTimeString() + " setting invites to " + settings.invitesAllowed); /*using (StreamWriter file = File.CreateText(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings.text")) { * JsonSerializer newserializer = new JsonSerializer(); * newserializer.Serialize(file, settings); * }*/ 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); } if (File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings")) { Console.WriteLine(DateTime.Now.ToShortTimeString() + " mod settings saved"); } else { Console.WriteLine(DateTime.Now.ToShortTimeString() + " mod settings not found after creation?!"); } await message.ModifyAsync(msg => msg.Content = "set invites allowed to " + settings.invitesAllowed.ToString().ToLower()); }
public async Task RemoveBadWord(string word) { if (!((SocketGuildUser)Context.User).HasAdmin()) { await ReplyAsync("You do have administrator permissions"); return; } ModerationFunctions.CheckDirectories(Context.Guild); List <BadWord> badWords; JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Ignore; if (!File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) { await ReplyAsync("No bad words file found"); return; } using (StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) using (JsonTextReader reader = new JsonTextReader(sr)) { badWords = serializer.Deserialize <List <BadWord> >(reader); } if (badWords == null) { await ReplyAsync("Bad words is null"); return; } BadWord badToRemove = null; foreach (BadWord badWord in badWords) { if (badWord.word == word) { badToRemove = badWord; } } if (badToRemove != null) { badWords.Remove(badToRemove); using (StreamWriter sw = new StreamWriter(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) using (JsonTextWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(sw, badWords); } await ReplyAsync("removed " + word + " from bad word list"); } else { await ReplyAsync("Bad word list doesn't contain " + word); } }
public async Task WarnUserSmallSizeAsync(SocketUser user, [Remainder] string reason) { if (!((SocketGuildUser)Context.User).CanWarn()) { await ReplyAsync("You do not have permission to use this command"); return; } ModerationFunctions.CheckDirectories(Context.Guild); ModerationFunctions.WarnUser(user, 1, reason, Context.Guild.OwnerId + "/Infractions/Games/" + user.Id); await ReplyAsync(user.Username + " has been warned for " + reason); }
public async Task AddBadWord(string word, string euphemism = null, float size = 0.5f) { if (!((SocketGuildUser)Context.User).HasAdmin()) { await ReplyAsync("You do have administrator permissions"); return; } ModerationFunctions.CheckDirectories(Context.Guild); BadWord badWord = new BadWord(); badWord.word = word; badWord.euphemism = euphemism; badWord.size = size; List <BadWord> badWords; JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Ignore; /*if (!File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) { * File.Create("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json"); * }*/ using (StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) using (JsonTextReader reader = new JsonTextReader(sr)) { badWords = serializer.Deserialize <List <BadWord> >(reader); } if (badWords == null) { badWords = new List <BadWord>(); } badWords.Add(badWord); using (StreamWriter sw = new StreamWriter(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) using (JsonTextWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(sw, badWords); } if (euphemism != null) { await ReplyAsync("added " + badWord.word + " also known as " + euphemism + " to bad word list"); } else { await ReplyAsync("added " + badWord.word + " to bad word list"); } }
public async Task CheckUserWarnsAsync(SocketUser user = null) { ModerationFunctions.CheckDirectories(Context.Guild); if (user == null) { user = Context.Message.Author; } if (File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id)) { await ReplyAsync(embed : ModerationFunctions.CheckInfractions(user, Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id)); } else { await ReplyAsync(user.Username + " has no warns"); } }
public async Task WarnUserAsync(SocketUser user, float size, [Remainder] string reason) { if (!((SocketGuildUser)Context.User).CanWarn()) { await ReplyAsync("You do not have permission to use this command"); return; } if (size > 999 || size < 0.01) { await ReplyAsync("Why would you need to warn someone with that size?"); return; } ModerationFunctions.CheckDirectories(Context.Guild); ModerationFunctions.WarnUser(user, size, reason, Context.Guild.OwnerId + "/Infractions/Games/" + user.Id); await ReplyAsync(user.Username + " has been warned for " + reason); }