fixed beam, thanks @LawlyPopz for implementing 99% of it

This commit is contained in:
Master Kwoth 2016-03-28 15:51:17 +02:00
parent 4b21da2e16
commit 7eb05080b0

View File

@ -1,16 +1,13 @@
using System; using Discord.Commands;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Modules; using NadekoBot.Modules;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
namespace NadekoBot.Commands namespace NadekoBot.Commands
{ {
@ -24,7 +21,8 @@ namespace NadekoBot.Commands
public StreamNotifications(DiscordModule module) : base(module) public StreamNotifications(DiscordModule module) : base(module)
{ {
checkTimer.Elapsed += async (s, e) => { checkTimer.Elapsed += async (s, e) =>
{
try try
{ {
var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams); var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams);
@ -91,8 +89,8 @@ namespace NadekoBot.Commands
case StreamNotificationConfig.StreamType.Beam: case StreamNotificationConfig.StreamType.Beam:
response = await SearchHelper.GetResponseStringAsync($"https://beam.pro/api/v1/channels/{stream.Username}"); response = await SearchHelper.GetResponseStringAsync($"https://beam.pro/api/v1/channels/{stream.Username}");
data = JObject.Parse(response); data = JObject.Parse(response);
isLive = data["online"].ToString() == "true"; isLive = data["online"].ToObject<bool>() == true;
return new Tuple<bool, string>(isLive, isLive ? data["viewersCurrent"].ToString() : "0"); return new Tuple<bool, string>(isLive, data["viewersCurrent"].ToString());
default: default:
break; break;
} }
@ -131,7 +129,8 @@ namespace NadekoBot.Commands
"\n**Usage**: ~rms SomeGuy") "\n**Usage**: ~rms SomeGuy")
.AddCheck(SimpleCheckers.ManageServer()) .AddCheck(SimpleCheckers.ManageServer())
.Parameter("username", ParameterType.Unparsed) .Parameter("username", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var username = e.GetArg("username")?.ToLower().Trim(); var username = e.GetArg("username")?.ToLower().Trim();
if (string.IsNullOrWhiteSpace(username)) if (string.IsNullOrWhiteSpace(username))
return; return;
@ -156,7 +155,8 @@ namespace NadekoBot.Commands
.Alias(Module.Prefix + "ls") .Alias(Module.Prefix + "ls")
.Description("Lists all streams you are following on this server." + .Description("Lists all streams you are following on this server." +
"\n**Usage**: ~ls") "\n**Usage**: ~ls")
.Do(async e => { .Do(async e =>
{
var config = SpecificConfigurations.Default.Of(e.Server.Id); var config = SpecificConfigurations.Default.Of(e.Server.Id);
@ -171,7 +171,8 @@ namespace NadekoBot.Commands
return; return;
} }
var text = string.Join("\n", streamsArray.Select(snc => { var text = string.Join("\n", streamsArray.Select(snc =>
{
try try
{ {
return $"`{snc.Username}`'s stream on **{e.Server.GetChannel(e.Channel.Id).Name}** channel. 【`{snc.Type.ToString()}`】"; return $"`{snc.Username}`'s stream on **{e.Server.GetChannel(e.Channel.Id).Name}** channel. 【`{snc.Type.ToString()}`】";
@ -185,7 +186,8 @@ namespace NadekoBot.Commands
} }
private Func<CommandEventArgs, Task> TrackStream(StreamNotificationConfig.StreamType type) => private Func<CommandEventArgs, Task> TrackStream(StreamNotificationConfig.StreamType type) =>
async e => { async e =>
{
var username = e.GetArg("username")?.ToLowerInvariant(); var username = e.GetArg("username")?.ToLowerInvariant();
if (string.IsNullOrWhiteSpace(username)) if (string.IsNullOrWhiteSpace(username))
return; return;