~ir error 400 should be more rare, closes #247
This commit is contained in:
parent
afbc970e52
commit
ad358b5e0f
@ -227,36 +227,36 @@ namespace NadekoBot.Modules.Conversations
|
|||||||
}
|
}
|
||||||
|
|
||||||
cgb.CreateCommand("slm")
|
cgb.CreateCommand("slm")
|
||||||
.Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)")
|
.Description("Shows the message where you were last mentioned in this channel (checks last 10k messages)")
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
|
|
||||||
Message msg = null;
|
Message msg = null;
|
||||||
var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false))
|
var msgs = (await e.Channel.DownloadMessages(100).ConfigureAwait(false))
|
||||||
.Where(m => m.MentionedUsers.Contains(e.User))
|
.Where(m => m.MentionedUsers.Contains(e.User))
|
||||||
.OrderByDescending(m => m.Timestamp);
|
.OrderByDescending(m => m.Timestamp);
|
||||||
if (msgs.Any())
|
if (msgs.Any())
|
||||||
msg = msgs.First();
|
msg = msgs.First();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var attempt = 0;
|
var attempt = 0;
|
||||||
Message lastMessage = null;
|
Message lastMessage = null;
|
||||||
while (msg == null && attempt++ < 5)
|
while (msg == null && attempt++ < 5)
|
||||||
{
|
{
|
||||||
var msgsarr = await e.Channel.DownloadMessages(100, lastMessage?.Id).ConfigureAwait(false);
|
var msgsarr = await e.Channel.DownloadMessages(100, lastMessage?.Id).ConfigureAwait(false);
|
||||||
msg = msgsarr
|
msg = msgsarr
|
||||||
.Where(m => m.MentionedUsers.Contains(e.User))
|
.Where(m => m.MentionedUsers.Contains(e.User))
|
||||||
.OrderByDescending(m => m.Timestamp)
|
.OrderByDescending(m => m.Timestamp)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
lastMessage = msgsarr.OrderBy(m => m.Timestamp).First();
|
lastMessage = msgsarr.OrderBy(m => m.Timestamp).First();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
await e.Channel.SendMessage($"Last message mentioning you was at {msg.Timestamp}\n**Message from {msg.User.Name}:** {msg.RawText}")
|
await e.Channel.SendMessage($"Last message mentioning you was at {msg.Timestamp}\n**Message from {msg.User.Name}:** {msg.RawText}")
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false);
|
await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("hide")
|
cgb.CreateCommand("hide")
|
||||||
.Description("Hides Nadeko in plain sight!11!!")
|
.Description("Hides Nadeko in plain sight!11!!")
|
||||||
|
@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
commands.Add(new StreamNotifications(this));
|
commands.Add(new StreamNotifications(this));
|
||||||
commands.Add(new ConverterCommand(this));
|
commands.Add(new ConverterCommand(this));
|
||||||
commands.Add(new RedditCommand(this));
|
commands.Add(new RedditCommand(this));
|
||||||
commands.Add(new WowJokeCommand(this));
|
commands.Add(new WowJokeCommand(this));
|
||||||
rng = new Random();
|
rng = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,9 +187,10 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
return;
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(e.GetArg("query"))}&cx=018084019232060951019%3Ahs5piey28-e&num=1&searchType=image&start={ rng.Next(1, 150) }&fields=items%2Flink&key={NadekoBot.Creds.GoogleAPIKey}";
|
var reqString = $"https://www.googleapis.com/customsearch/v1?q={Uri.EscapeDataString(e.GetArg("query"))}&cx=018084019232060951019%3Ahs5piey28-e&num=50&searchType=image&start={ rng.Next(1, 50) }&fields=items%2Flink&key={NadekoBot.Creds.GoogleAPIKey}";
|
||||||
var obj = JObject.Parse(await SearchHelper.GetResponseStringAsync(reqString).ConfigureAwait(false));
|
var obj = JObject.Parse(await SearchHelper.GetResponseStringAsync(reqString).ConfigureAwait(false));
|
||||||
await e.Channel.SendMessage(obj["items"][0]["link"].ToString()).ConfigureAwait(false);
|
var items = obj["items"] as JArray;
|
||||||
|
await e.Channel.SendMessage(items[rng.Next(0, items.Count)]["link"].ToString()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (HttpRequestException exception)
|
catch (HttpRequestException exception)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user