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:
@ -27,6 +27,7 @@ namespace NadekoBot.Modules.Administration
|
||||
commands.Add(new CustomReactionsCommands(this));
|
||||
commands.Add(new AutoAssignRole(this));
|
||||
commands.Add(new SelfCommands(this));
|
||||
commands.Add(new IncidentsCommands(this));
|
||||
|
||||
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))
|
||||
{
|
||||
await args.Message.Delete().ConfigureAwait(false);
|
||||
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}]]");
|
||||
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.\n" +
|
||||
$"`Full message:` {args.Message.Text}");
|
||||
if (serverPerms.Verbose)
|
||||
await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " +
|
||||
$"allowed on this channel.")
|
||||
|
@ -23,9 +23,9 @@ namespace NadekoBot.Modules.Permissions.Commands
|
||||
if (serverPerms.Words.Any(w => wordsInMessage.Contains(w)))
|
||||
{
|
||||
await args.Message.Delete().ConfigureAwait(false);
|
||||
IncidentsHandler.Add(args.Server.Id, $"User [{args.User.Name}/{args.User.Id}] posted " +
|
||||
$"BANNED WORD in [{args.Channel.Name}/{args.Channel.Id}] channel. " +
|
||||
$"Full message: [[{args.Message.Text}]]");
|
||||
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.\n" +
|
||||
$"`Full message:` {args.Message.Text}");
|
||||
if (serverPerms.Verbose)
|
||||
await args.Channel.SendMessage($"{args.User.Mention} One or more of the words you used " +
|
||||
$"in that sentence are not allowed here.")
|
||||
|
Reference in New Issue
Block a user