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; return;
} }
var roleName = args[0].ToUpperInvariant(); 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) if (role == null)
{ {
@ -254,7 +254,7 @@ namespace NadekoBot.Modules.Administration
{ {
msg = "❗No reason provided."; 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."); await channel.SendErrorAsync("⚠️ You can't use this command on users with a role higher or equal to yours in the role hierarchy.");
return; return;
@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Administration
{ {
foreach (var u in users) 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); await channel.SendConfirmAsync("🔇 **Deafen** successful.").ConfigureAwait(false);
} }
@ -390,7 +390,7 @@ namespace NadekoBot.Modules.Administration
{ {
foreach (var u in users) 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); await channel.SendConfirmAsync("🔊 **Undeafen** successful.").ConfigureAwait(false);
} }
@ -650,8 +650,10 @@ namespace NadekoBot.Modules.Administration
cnt -= 100; cnt -= 100;
} }
var title = $"Chatlog-{channel.Guild.Name}/#{channel.Name}-{DateTime.Now}.txt"; 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 (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); title, title).ConfigureAwait(false);
} }
@ -667,7 +669,7 @@ namespace NadekoBot.Modules.Administration
foreach (var role in roles) foreach (var role in roles)
{ {
send += $"\n**{role.Name}**\n"; 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) while (send.Length > 2000)

View File

@ -834,6 +834,8 @@ namespace NadekoBot.Modules.Searches
website = $"https://yande.re/post.xml?limit=100&tags={tag}"; website = $"https://yande.re/post.xml?limit=100&tags={tag}";
break; break;
} }
try
{
using (var http = new HttpClient()) using (var http = new HttpClient())
{ {
http.AddFakeHeaders(); http.AddFakeHeaders();
@ -849,6 +851,11 @@ namespace NadekoBot.Modules.Searches
return url; return url;
} }
} }
catch
{
return null;
}
}
public static async Task<bool> ValidateQuery(ITextChannel ch, string query) public static async Task<bool> ValidateQuery(ITextChannel ch, string query)
{ {
if (!string.IsNullOrEmpty(query.Trim())) return true; if (!string.IsNullOrEmpty(query.Trim())) return true;