private Func <CommandEventArgs, Task> TrackStream(StreamNotificationConfig.StreamType type) => async e => { var username = e.GetArg("username"); if (string.IsNullOrWhiteSpace(username)) { return; } var config = SpecificConfigurations.Default.Of(e.Server.Id); var stream = new StreamNotificationConfig { ServerId = e.Server.Id, ChannelId = e.Channel.Id, Username = username, Type = type, }; var exists = config.ObservingStreams.Contains(stream); if (exists) { await e.Channel.SendMessage(":anger: I am already notifying that stream on this channel."); } Tuple <bool, string> data; try { data = await GetStreamStatus(stream); } catch { await e.Channel.SendMessage(":anger: Stream probably doesn't exist."); return; } var msg = $"Stream is currently **{(data.Item1 ? "ONLINE" : "OFFLINE")}** with **{data.Item2}** viewers"; if (data.Item1) { if (type == StreamNotificationConfig.StreamType.Hitbox) { msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】"; } else if (type == StreamNotificationConfig.StreamType.Twitch) { msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】"; } else if (type == StreamNotificationConfig.StreamType.YoutubeGaming) { msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}"; } } stream.LastStatus = data.Item1; if (!exists) { msg = $":ok: I will notify this channel when status changes.\n{msg}"; } await e.Channel.SendMessage(msg); config.ObservingStreams.Add(stream); };
private Func <CommandEventArgs, Task> TrackStream(StreamNotificationConfig.StreamType type) => async e => { var username = e.GetArg("username")?.ToLowerInvariant(); if (string.IsNullOrWhiteSpace(username)) { return; } var config = SpecificConfigurations.Default.Of(e.Server.Id); var stream = new StreamNotificationConfig { ServerId = e.Server.Id, ChannelId = e.Channel.Id, Username = username, Type = type, }; var exists = config.ObservingStreams.Contains(stream); if (exists) { await e.Channel.SendMessage(":anger: Ich benachrichtige diesen Channel schon über diesen Stream.").ConfigureAwait(false); } Tuple <bool, string> data; try { data = await GetStreamStatus(stream).ConfigureAwait(false); } catch { await e.Channel.SendMessage(":anger: Stream existiert wahrscheinlich nicht.").ConfigureAwait(false); return; } var msg = $"Stream ist derzeit **{(data.Item1 ? "ONLINE" : "OFFLINE")}** mit **{data.Item2}** Zuschauern"; if (data.Item1) { if (type == StreamNotificationConfig.StreamType.Hitbox) { msg += $"\n`Hier ist der Link:`【 http://www.hitbox.tv/{stream.Username}/ 】"; } else if (type == StreamNotificationConfig.StreamType.Twitch) { msg += $"\n`Hier ist der Link:`【 http://www.twitch.tv/{stream.Username}/ 】"; } else if (type == StreamNotificationConfig.StreamType.Beam) { msg += $"\n`Here is the Link:`【 https://beam.pro/{stream.Username}/ 】"; } else if (type == StreamNotificationConfig.StreamType.YoutubeGaming) { msg += $"\n`Hier ist der Link:`【 Derzeit nicht implementiert - {stream.Username} 】"; } } stream.LastStatus = data.Item1; if (!exists) { msg = $":ok: Ich werde diesen Channel benachrichtigen wenn sich der Status ändert.\n{msg}"; } await e.Channel.SendMessage(msg).ConfigureAwait(false); config.ObservingStreams.Add(stream); };