Greatly improved incidents. you can now list unread incidents with .lin, and get .txt of all incidents with .lain command
				
					
				
			This commit is contained in:
		@@ -103,6 +103,14 @@ namespace NadekoBot.Classes
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        internal void UpdateAll<T>(IEnumerable<T> objs) where T : IDataModel
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            using (var conn = new SQLiteConnection(FilePath))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                conn.UpdateAll(objs);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        internal HashSet<T> GetAllRows<T>() where T : IDataModel, new()
 | 
					        internal HashSet<T> GetAllRows<T>() where T : IDataModel, new()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using (var conn = new SQLiteConnection(FilePath))
 | 
					            using (var conn = new SQLiteConnection(FilePath))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,25 @@
 | 
				
			|||||||
using System;
 | 
					using NadekoBot.DataModels;
 | 
				
			||||||
using System.IO;
 | 
					using System;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Classes
 | 
					namespace NadekoBot.Classes
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    internal static class IncidentsHandler
 | 
					    internal static class IncidentsHandler
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public static void Add(ulong serverId, string text)
 | 
					        public static void Add(ulong serverId, ulong channelId, string text)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Directory.CreateDirectory("data/incidents");
 | 
					 | 
				
			||||||
            File.AppendAllText($"data/incidents/{serverId}.txt", text + "\n--------------------------\n");
 | 
					 | 
				
			||||||
            var def = Console.ForegroundColor;
 | 
					            var def = Console.ForegroundColor;
 | 
				
			||||||
            Console.ForegroundColor = ConsoleColor.Red;
 | 
					            Console.ForegroundColor = ConsoleColor.Red;
 | 
				
			||||||
            Console.WriteLine($"INCIDENT: {text}");
 | 
					            Console.WriteLine($"INCIDENT: {text}");
 | 
				
			||||||
            Console.ForegroundColor = def;
 | 
					            Console.ForegroundColor = def;
 | 
				
			||||||
 | 
					            var incident = new Incident
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ChannelId = (long)channelId,
 | 
				
			||||||
 | 
					                ServerId = (long)serverId,
 | 
				
			||||||
 | 
					                Text = text,
 | 
				
			||||||
 | 
					                Read = false
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            DbHandler.Instance.InsertData<Incident>(incident);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ namespace NadekoBot.Modules.Administration
 | 
				
			|||||||
            commands.Add(new CustomReactionsCommands(this));
 | 
					            commands.Add(new CustomReactionsCommands(this));
 | 
				
			||||||
            commands.Add(new AutoAssignRole(this));
 | 
					            commands.Add(new AutoAssignRole(this));
 | 
				
			||||||
            commands.Add(new SelfCommands(this));
 | 
					            commands.Add(new SelfCommands(this));
 | 
				
			||||||
 | 
					            commands.Add(new IncidentsCommands(this));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            NadekoBot.Client.GetService<CommandService>().CommandExecuted += DeleteCommandMessage;
 | 
					            NadekoBot.Client.GetService<CommandService>().CommandExecuted += DeleteCommandMessage;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					using Discord.Commands;
 | 
				
			||||||
 | 
					using NadekoBot.Classes;
 | 
				
			||||||
 | 
					using NadekoBot.DataModels;
 | 
				
			||||||
 | 
					using NadekoBot.Modules.Permissions.Classes;
 | 
				
			||||||
 | 
					using System.IO;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace NadekoBot.Modules.Administration.Commands
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    internal class IncidentsCommands : DiscordCommand
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public IncidentsCommands(DiscordModule module) : base(module) { }
 | 
				
			||||||
 | 
					        internal override void Init(CommandGroupBuilder cgb)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            cgb.CreateCommand(Module.Prefix + "listincidents")
 | 
				
			||||||
 | 
					                .Alias(Prefix + "lin")
 | 
				
			||||||
 | 
					                .Description("List all UNREAD incidents and flags them as read.")
 | 
				
			||||||
 | 
					                .AddCheck(SimpleCheckers.ManageServer())
 | 
				
			||||||
 | 
					                .Do(async e =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var sid = (long)e.Server.Id;
 | 
				
			||||||
 | 
					                    var incs = DbHandler.Instance.FindAll<Incident>(i => i.ServerId == sid && i.Read == false);
 | 
				
			||||||
 | 
					                    DbHandler.Instance.UpdateAll<Incident>(incs.Select(i => { i.Read = true; return i; }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await e.User.SendMessage(string.Join("\n----------------------", incs.Select(i => i.Text)));
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            cgb.CreateCommand(Module.Prefix + "listallincidents")
 | 
				
			||||||
 | 
					                .Alias(Prefix + "lain")
 | 
				
			||||||
 | 
					                .Description("Sends you a file containing all incidents and flags them as read.")
 | 
				
			||||||
 | 
					                .AddCheck(SimpleCheckers.ManageServer())
 | 
				
			||||||
 | 
					                .Do(async e =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var sid = (long)e.Server.Id;
 | 
				
			||||||
 | 
					                    var incs = DbHandler.Instance.FindAll<Incident>(i => i.ServerId == sid);
 | 
				
			||||||
 | 
					                    DbHandler.Instance.UpdateAll<Incident>(incs.Select(i => { i.Read = true; return i; }));
 | 
				
			||||||
 | 
					                    var data = string.Join("\n----------------------\n", incs.Select(i => i.Text));
 | 
				
			||||||
 | 
					                    MemoryStream ms = new MemoryStream();
 | 
				
			||||||
 | 
					                    var sw = new StreamWriter(ms);
 | 
				
			||||||
 | 
					                    sw.WriteLine(data);
 | 
				
			||||||
 | 
					                    sw.Flush();
 | 
				
			||||||
 | 
					                    sw.BaseStream.Position = 0;
 | 
				
			||||||
 | 
					                    await e.User.SendFile("incidents.txt", sw.BaseStream);
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -25,9 +25,9 @@ namespace NadekoBot.Modules.Permissions.Commands
 | 
				
			|||||||
                    if (filterRegex.IsMatch(args.Message.RawText))
 | 
					                    if (filterRegex.IsMatch(args.Message.RawText))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        await args.Message.Delete().ConfigureAwait(false);
 | 
					                        await args.Message.Delete().ConfigureAwait(false);
 | 
				
			||||||
                        IncidentsHandler.Add(args.Server.Id, $"User [{args.User.Name}/{args.User.Id}] posted " +
 | 
					                        IncidentsHandler.Add(args.Server.Id, args.Channel.Id, $"User [{args.User.Name}/{args.User.Id}] posted " +
 | 
				
			||||||
                                                             $"INVITE LINK in [{args.Channel.Name}/{args.Channel.Id}] channel. " +
 | 
					                                                             $"INVITE LINK in [{args.Channel.Name}/{args.Channel.Id}] channel.\n" +
 | 
				
			||||||
                                                             $"Full message: [[{args.Message.Text}]]");
 | 
					                                                             $"`Full message:` {args.Message.Text}");
 | 
				
			||||||
                        if (serverPerms.Verbose)
 | 
					                        if (serverPerms.Verbose)
 | 
				
			||||||
                            await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " +
 | 
					                            await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " +
 | 
				
			||||||
                                                           $"allowed on this channel.")
 | 
					                                                           $"allowed on this channel.")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,9 +23,9 @@ namespace NadekoBot.Modules.Permissions.Commands
 | 
				
			|||||||
                    if (serverPerms.Words.Any(w => wordsInMessage.Contains(w)))
 | 
					                    if (serverPerms.Words.Any(w => wordsInMessage.Contains(w)))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        await args.Message.Delete().ConfigureAwait(false);
 | 
					                        await args.Message.Delete().ConfigureAwait(false);
 | 
				
			||||||
                        IncidentsHandler.Add(args.Server.Id, $"User [{args.User.Name}/{args.User.Id}] posted " +
 | 
					                        IncidentsHandler.Add(args.Server.Id, args.Channel.Id, $"User [{args.User.Name}/{args.User.Id}] posted " +
 | 
				
			||||||
                                                             $"BANNED WORD in [{args.Channel.Name}/{args.Channel.Id}] channel. " +
 | 
					                                                             $"BANNED WORD in [{args.Channel.Name}/{args.Channel.Id}] channel.\n" +
 | 
				
			||||||
                                                             $"Full message: [[{args.Message.Text}]]");
 | 
					                                                             $"`Full message:` {args.Message.Text}");
 | 
				
			||||||
                        if (serverPerms.Verbose)
 | 
					                        if (serverPerms.Verbose)
 | 
				
			||||||
                            await args.Channel.SendMessage($"{args.User.Mention} One or more of the words you used " +
 | 
					                            await args.Channel.SendMessage($"{args.User.Mention} One or more of the words you used " +
 | 
				
			||||||
                                                           $"in that sentence are not allowed here.")
 | 
					                                                           $"in that sentence are not allowed here.")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -136,6 +136,7 @@
 | 
				
			|||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <Compile Include="Modules\Administration\Commands\AutoAssignRole.cs" />
 | 
					    <Compile Include="Modules\Administration\Commands\AutoAssignRole.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Administration\Commands\CustomReactionsCommands.cs" />
 | 
					    <Compile Include="Modules\Administration\Commands\CustomReactionsCommands.cs" />
 | 
				
			||||||
 | 
					    <Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand - Copy.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Administration\Commands\SelfCommands.cs" />
 | 
					    <Compile Include="Modules\Administration\Commands\SelfCommands.cs" />
 | 
				
			||||||
    <Compile Include="Modules\ClashOfClans\ClashOfClans.cs" />
 | 
					    <Compile Include="Modules\ClashOfClans\ClashOfClans.cs" />
 | 
				
			||||||
    <Compile Include="Classes\DBHandler.cs" />
 | 
					    <Compile Include="Classes\DBHandler.cs" />
 | 
				
			||||||
@@ -192,7 +193,7 @@
 | 
				
			|||||||
    <Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" />
 | 
					    <Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Utility\Commands\InfoCommands.cs" />
 | 
					    <Compile Include="Modules\Utility\Commands\InfoCommands.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Utility\Commands\Remind.cs" />
 | 
					    <Compile Include="Modules\Utility\Commands\Remind.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" />
 | 
					    <Compile Include="Modules\Administration\Commands\IncidentsCommands.cs" />
 | 
				
			||||||
    <Compile Include="Modules\ClashOfClans\ClashOfClansModule.cs" />
 | 
					    <Compile Include="Modules\ClashOfClans\ClashOfClansModule.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Permissions\Commands\FilterWordsCommand.cs" />
 | 
					    <Compile Include="Modules\Permissions\Commands\FilterWordsCommand.cs" />
 | 
				
			||||||
    <Compile Include="Modules\Permissions\Commands\FilterInvitesCommand.cs" />
 | 
					    <Compile Include="Modules\Permissions\Commands\FilterInvitesCommand.cs" />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,10 @@
 | 
				
			|||||||
using System;
 | 
					namespace NadekoBot.DataModels
 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace NadekoBot.DataModels
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    class Incident : IDataModel
 | 
					    class Incident : IDataModel
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public long ServerId { get; set; }
 | 
					        public long ServerId { get; set; }
 | 
				
			||||||
        public long ChannelId { get; set; }
 | 
					        public long ChannelId { get; set; }
 | 
				
			||||||
        public string Text { get; set; }
 | 
					        public string Text { get; set; }
 | 
				
			||||||
        public DateTime When { get; set; }
 | 
					 | 
				
			||||||
        public bool Read { get; set; } = false;
 | 
					        public bool Read { get; set; } = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user