From 0b20e8536a471deb736a72ec94ced6757fe36d57 Mon Sep 17 00:00:00 2001 From: rox666 Date: Wed, 20 Apr 2016 20:13:39 +0200 Subject: [PATCH] Update SearchesModule.cs Bot tells you, when you reached your daily limit with the Google Api. --- NadekoBot/Modules/Searches/SearchesModule.cs | 31 +++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/NadekoBot/Modules/Searches/SearchesModule.cs b/NadekoBot/Modules/Searches/SearchesModule.cs index 948dbe3c..1a618719 100644 --- a/NadekoBot/Modules/Searches/SearchesModule.cs +++ b/NadekoBot/Modules/Searches/SearchesModule.cs @@ -14,6 +14,7 @@ using System.Drawing; using System.IO; using System.Linq; using System.Net; +using System.Net.Http; namespace NadekoBot.Modules.Searches { @@ -157,10 +158,17 @@ $@"🌍 **Weather for** 【{obj["target"]}】 var obj = JObject.Parse(await SearchHelper.GetResponseStringAsync(reqString).ConfigureAwait(false)); await e.Channel.SendMessage(obj["items"][0]["link"].ToString()).ConfigureAwait(false); } - catch (Exception ex) - { - await e.Channel.SendMessage($"💢 {ex.Message}").ConfigureAwait(false); - } + catch (HttpRequestException exception) + { + if (exception.Message.Contains ("403 (Forbidden)")) + { + await e.Channel.SendMessage ("Daily limit reached!") + } + else + { + await e.Channel.SendMessage ("Something went wrong."); + } + } }); cgb.CreateCommand(Prefix + "ir") @@ -176,10 +184,17 @@ $@"🌍 **Weather for** 【{obj["target"]}】 var obj = JObject.Parse(await SearchHelper.GetResponseStringAsync(reqString).ConfigureAwait(false)); await e.Channel.SendMessage(obj["items"][0]["link"].ToString()).ConfigureAwait(false); } - catch (Exception ex) - { - await e.Channel.SendMessage($"💢 {ex.Message}").ConfigureAwait(false); - } + catch (HttpRequestException exception) + { + if (exception.Message.Contains ("403 (Forbidden)")) + { + await e.Channel.SendMessage ("Daily limit reached!") + } + else + { + await e.Channel.SendMessage ("Something went wrong."); + } + } }); cgb.CreateCommand(Prefix + "lmgtfy") .Description("Google something for an idiot.")