From a21a66f3c1cac39a16f00ec793bda999828cc6af Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 12 Mar 2016 16:55:01 +0100 Subject: [PATCH] cross server channels, logging when someone posts a link to console and incidents.txt --- NadekoBot/Classes/IncidentsHandler.cs | 16 ++++++++++++++++ NadekoBot/Classes/Permissions/SimpleCheckers.cs | 11 ++++++----- NadekoBot/Commands/FilterInvitesCommand.cs | 8 +++++++- NadekoBot/Modules/Administration.cs | 2 +- NadekoBot/Modules/Games.cs | 2 +- NadekoBot/NadekoBot.csproj | 2 ++ 6 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 NadekoBot/Classes/IncidentsHandler.cs diff --git a/NadekoBot/Classes/IncidentsHandler.cs b/NadekoBot/Classes/IncidentsHandler.cs new file mode 100644 index 00000000..1743e020 --- /dev/null +++ b/NadekoBot/Classes/IncidentsHandler.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Classes { + class IncidentsHandler { + public static void Add(ulong serverId, string text) { + Directory.CreateDirectory("data/incidents"); + File.AppendAllText($"data/incidents/{serverId}.txt", text + "\n--------------------------"); + Console.WriteLine($"INCIDENT: {text}"); + } + } +} diff --git a/NadekoBot/Classes/Permissions/SimpleCheckers.cs b/NadekoBot/Classes/Permissions/SimpleCheckers.cs index eabb0147..43763605 100644 --- a/NadekoBot/Classes/Permissions/SimpleCheckers.cs +++ b/NadekoBot/Classes/Permissions/SimpleCheckers.cs @@ -4,8 +4,7 @@ using System; using Discord.Commands.Permissions; namespace NadekoBot.Classes.Permissions { - public static class SimpleCheckers - { + public static class SimpleCheckers { public static ManageRoles CanManageRoles { get; } = new ManageRoles(); public static Func OwnerOnly() => @@ -17,11 +16,13 @@ namespace NadekoBot.Classes.Permissions { public static Func ManageChannels() => (com, user, ch) => user.ServerPermissions.ManageChannels; - public class ManageRoles :IPermissionChecker - { + public static Func ManageServer() => + (com, user, ch) => user.ServerPermissions.ManageServer; + + public class ManageRoles : IPermissionChecker { public bool CanRun(Command command, User user, Channel channel, out string error) { error = string.Empty; - if(user.ServerPermissions.ManageRoles) + if (user.ServerPermissions.ManageRoles) return true; error = "You do not have a permission to manage roles."; return false; diff --git a/NadekoBot/Commands/FilterInvitesCommand.cs b/NadekoBot/Commands/FilterInvitesCommand.cs index e5342b77..886cfd07 100644 --- a/NadekoBot/Commands/FilterInvitesCommand.cs +++ b/NadekoBot/Commands/FilterInvitesCommand.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Discord; using Discord.Commands; +using NadekoBot.Classes; using NadekoBot.Classes.Permissions; using NadekoBot.Modules; using ServerPermissions = NadekoBot.Classes.Permissions.ServerPermissions; @@ -17,14 +18,19 @@ namespace NadekoBot.Commands { public FilterInvitesCommand(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += async (sender, args) => { + if (args.Channel.IsPrivate) return; try { ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return; if (filterRegex.IsMatch(args.Message.RawText)) { await args.Message.Delete(); + IncidentsHandler.Add(args.Server.Id, $"User [{args.User.Name}/{args.User.Id}] posted " + + $"INVITE LINK in [{args.Channel.Name}/{args.Channel.Id}] channel. " + + $"Full message: [[{args.Message.Text}]]"); if (serverPerms.Verbose) - await args.Channel.SendMessage($"{args.User.Mention} Invite links are not allowed on this channel."); + await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " + + $"allowed on this channel."); } } catch { } }; diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 22f67efc..e8babf0a 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Modules { commands.Add(new PlayingRotate(this)); commands.Add(new RatelimitCommand(this)); commands.Add(new VoicePlusTextCommand(this)); - //commands.Add(new CrossServerTextChannel(this)); + commands.Add(new CrossServerTextChannel(this)); } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; diff --git a/NadekoBot/Modules/Games.cs b/NadekoBot/Modules/Games.cs index 901dbb18..c8fadda4 100644 --- a/NadekoBot/Modules/Games.cs +++ b/NadekoBot/Modules/Games.cs @@ -16,7 +16,7 @@ namespace NadekoBot.Modules { commands.Add(new Trivia(this)); commands.Add(new SpeedTyping(this)); commands.Add(new PollCommand(this)); - commands.Add(new BetrayGame(this)); + //commands.Add(new BetrayGame(this)); _8BallAnswers = JArray.Parse(File.ReadAllText("data/8ball.json")).Select(t => t.ToString()).ToArray(); } diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 574a2afb..0cc311c7 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -118,6 +118,7 @@ + @@ -144,6 +145,7 @@ +