Fixes. Improved .savechat

This commit is contained in:
Kwoth 2016-12-26 08:28:48 +01:00
parent 3bad28aa18
commit 94f1657a03
2 changed files with 33 additions and 24 deletions

View File

@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Administration
return;
}
var roleName = args[0].ToUpperInvariant();
var role = channel.Guild.Roles.Where(r=>r.Name.ToUpperInvariant() == roleName).FirstOrDefault();
var role = channel.Guild.Roles.Where(r => r.Name.ToUpperInvariant() == roleName).FirstOrDefault();
if (role == null)
{
@ -254,7 +254,7 @@ namespace NadekoBot.Modules.Administration
{
msg = "❗No reason provided.";
}
if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Select(r=>r.Position).Max() >= ((IGuildUser)umsg.Author).Roles.Select(r => r.Position).Max())
if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Select(r => r.Position).Max() >= ((IGuildUser)umsg.Author).Roles.Select(r => r.Position).Max())
{
await channel.SendErrorAsync("⚠️ You can't use this command on users with a role higher or equal to yours in the role hierarchy.");
return;
@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Administration
{
foreach (var u in users)
{
await u.ModifyAsync(usr=>usr.Deaf = true).ConfigureAwait(false);
await u.ModifyAsync(usr => usr.Deaf = true).ConfigureAwait(false);
}
await channel.SendConfirmAsync("🔇 **Deafen** successful.").ConfigureAwait(false);
}
@ -390,7 +390,7 @@ namespace NadekoBot.Modules.Administration
{
foreach (var u in users)
{
await u.ModifyAsync(usr=> usr.Deaf = false).ConfigureAwait(false);
await u.ModifyAsync(usr => usr.Deaf = false).ConfigureAwait(false);
}
await channel.SendConfirmAsync("🔊 **Undeafen** successful.").ConfigureAwait(false);
}
@ -650,8 +650,10 @@ namespace NadekoBot.Modules.Administration
cnt -= 100;
}
var title = $"Chatlog-{channel.Guild.Name}/#{channel.Name}-{DateTime.Now}.txt";
var grouping = msgs.GroupBy(x => $"{x.CreatedAt.Date:dd.MM.yyyy}")
.Select(g => new { date = g.Key, messages = g.Select(s => $"【{s.Timestamp:HH:mm:ss}】{s.Author}:" + s.ToString()) });
await (umsg.Author as IGuildUser).SendFileAsync(
await JsonConvert.SerializeObject(new { Messages = msgs.Select(s => $"【{s.Timestamp:HH:mm:ss}】{s.Author}:" + s.ToString()) }, Formatting.Indented).ToStream().ConfigureAwait(false),
await JsonConvert.SerializeObject(grouping, Formatting.Indented).ToStream().ConfigureAwait(false),
title, title).ConfigureAwait(false);
}
@ -667,7 +669,7 @@ namespace NadekoBot.Modules.Administration
foreach (var role in roles)
{
send += $"\n**{role.Name}**\n";
send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct().Select(u=>u.Mention));
send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct().Select(u => u.Mention));
}
while (send.Length > 2000)

View File

@ -834,19 +834,26 @@ namespace NadekoBot.Modules.Searches
website = $"https://yande.re/post.xml?limit=100&tags={tag}";
break;
}
using (var http = new HttpClient())
try
{
http.AddFakeHeaders();
var data = await http.GetStreamAsync(website);
var doc = new XmlDocument();
doc.Load(data);
using (var http = new HttpClient())
{
http.AddFakeHeaders();
var data = await http.GetStreamAsync(website);
var doc = new XmlDocument();
doc.Load(data);
var node = doc.LastChild.ChildNodes[new NadekoRandom().Next(0, doc.LastChild.ChildNodes.Count)];
var node = doc.LastChild.ChildNodes[new NadekoRandom().Next(0, doc.LastChild.ChildNodes.Count)];
var url = node.Attributes["file_url"].Value;
if (!url.StartsWith("http"))
url = "https:" + url;
return url;
var url = node.Attributes["file_url"].Value;
if (!url.StartsWith("http"))
url = "https:" + url;
return url;
}
}
catch
{
return null;
}
}
public static async Task<bool> ValidateQuery(ITextChannel ch, string query)