Fixed twitch stream, and response messages.

This commit is contained in:
Kwoth 2016-09-18 18:30:18 +02:00
parent bc3010cef2
commit 798567ee5d

View File

@ -109,13 +109,13 @@ namespace NadekoBot.Modules.Searches.Commands
cachedStatuses.TryAdd(hitboxUrl, result); cachedStatuses.TryAdd(hitboxUrl, result);
return result; return result;
case StreamNotificationConfig.StreamType.Twitch: case StreamNotificationConfig.StreamType.Twitch:
var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}"; var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6";
if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result))
return result; return result;
response = await SearchHelper.GetResponseStringAsync(twitchUrl).ConfigureAwait(false); response = await SearchHelper.GetResponseStringAsync(twitchUrl).ConfigureAwait(false);
data = JObject.Parse(response); data = JObject.Parse(response);
isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString()); isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString());
result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : "0"); result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : stream.Username);
cachedStatuses.TryAdd(twitchUrl, result); cachedStatuses.TryAdd(twitchUrl, result);
return result; return result;
case StreamNotificationConfig.StreamType.Beam: case StreamNotificationConfig.StreamType.Beam:
@ -131,7 +131,7 @@ namespace NadekoBot.Modules.Searches.Commands
default: default:
break; break;
} }
return new Tuple<bool, string>(false, "0"); return new Tuple<bool, string>(false, "NOT_FOUND");
} }
internal override void Init(CommandGroupBuilder cgb) internal override void Init(CommandGroupBuilder cgb)
@ -180,7 +180,11 @@ namespace NadekoBot.Modules.Searches.Commands
})); }));
if (streamStatus.Item1) if (streamStatus.Item1)
{ {
await e.Channel.SendMessage($"`Streamer {streamStatus.Item2} is online.`"); await e.Channel.SendMessage($"`Streamer {stream} is online with {streamStatus.Item2} viewers.`");
}
else
{
await e.Channel.SendMessage($"`Streamer {stream} is offline.`");
} }
} }
catch catch
@ -209,7 +213,11 @@ namespace NadekoBot.Modules.Searches.Commands
})); }));
if (streamStatus.Item1) if (streamStatus.Item1)
{ {
await e.Channel.SendMessage($"`Streamer {streamStatus.Item2} is online.`"); await e.Channel.SendMessage($"`Streamer {stream} is online with {streamStatus.Item2} viewers.`");
}
else
{
await e.Channel.SendMessage($"`Streamer {stream} is offline.`");
} }
} }
catch catch
@ -238,7 +246,11 @@ namespace NadekoBot.Modules.Searches.Commands
})); }));
if (streamStatus.Item1) if (streamStatus.Item1)
{ {
await e.Channel.SendMessage($"`Streamer {streamStatus.Item2} is online.`"); await e.Channel.SendMessage($"`Streamer {stream} is online with {streamStatus.Item2} viewers.`");
}
else
{
await e.Channel.SendMessage($"`Streamer {stream} is offline.`");
} }
} }
catch catch