.savechat added, added .ToStream extension for strings
This commit is contained in:
parent
59eef96009
commit
dd349376a2
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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<Message>(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());
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user