diff --git a/NadekoBot/Classes/Extensions.cs b/NadekoBot/Classes/Extensions.cs index 93527acd..1b162209 100644 --- a/NadekoBot/Classes/Extensions.cs +++ b/NadekoBot/Classes/Extensions.cs @@ -215,7 +215,7 @@ namespace NadekoBot.Extensions sb.Append($"{ Format.Code(item.Key)}\n"); sb.AppendLine(" `└─`" + Format.Bold(item.Value)); } - + } else { @@ -224,7 +224,7 @@ namespace NadekoBot.Extensions sb.Append($"{ Format.Code(item.ToString())} \n"); } } - + return sb.ToString(); } /// @@ -352,5 +352,15 @@ namespace NadekoBot.Extensions await Task.Run(() => images.Merge(reverseScaleFactor)).ConfigureAwait(false); public static string Unmention(this string str) => str.Replace("@", "ම"); + + public static Stream ToStream(this string str) + { + var sw = new StreamWriter(new MemoryStream()); + sw.Write(str); + sw.Flush(); + sw.BaseStream.Position = 0; + return sw.BaseStream; + } + } } diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 8689ea4a..8095ad0a 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -6,8 +6,11 @@ using NadekoBot.DataModels; using NadekoBot.Extensions; using NadekoBot.Modules.Administration.Commands; using NadekoBot.Modules.Permissions.Classes; +using Newtonsoft.Json; using System; +using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading.Tasks; namespace NadekoBot.Modules.Administration @@ -902,6 +905,33 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage("`Done.`").ConfigureAwait(false); }); + cgb.CreateCommand(Prefix + "savechat") + .Description("Saves a number of messages to a text file and sends it to you. **Bot Owner Only** | `.chatsave 150`") + .Parameter("cnt", ParameterType.Required) + .AddCheck(SimpleCheckers.OwnerOnly()) + .Do(async e => + { + var cntstr = e.GetArg("cnt")?.Trim(); + int cnt; + if (!int.TryParse(cntstr, out cnt)) + return; + ulong? lastmsgId = null; + var sb = new StringBuilder(); + var msgs = new List(cnt); + while (cnt > 0) + { + var dlcnt = cnt < 100 ? cnt : 100; + + var dledMsgs = await e.Channel.DownloadMessages(dlcnt, lastmsgId); + if (!dledMsgs.Any()) + break; + msgs.AddRange(dledMsgs); + lastmsgId = msgs[msgs.Count - 1].Id; + cnt -= 100; + } + await e.User.SendFile($"Chatlog-{e.Server.Name}/#{e.Channel.Name}-{DateTime.Now}.txt", JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream()); + }); + }); } } diff --git a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs index baf177b6..4aba4b10 100644 --- a/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/CustomReactionsCommands.cs @@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Administration.Commands cgb.CreateCommand(Prefix + "editcustreact") .Alias(Prefix + "ecr") - .Description("Edits a custom reaction, arguments are custom reactions name, index to change, and a (multiword) message | `.ecr \"%mention% disguise\" 2 Test 123`") + .Description("Edits a custom reaction, arguments are custom reactions name, index to change, and a (multiword) message **Bot Owner Only** | `.ecr \"%mention% disguise\" 2 Test 123`") .Parameter("name", ParameterType.Required) .Parameter("index", ParameterType.Required) .Parameter("message", ParameterType.Unparsed)