From 68031183cdd9c1db483d41a215475cc89c8dd607 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 18:18:51 +0530 Subject: [PATCH 01/43] Update StreamNotificationCommands.cs --- .../Searches/Commands/StreamNotificationCommands.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index db9e3c17..7bf7abab 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -274,10 +274,10 @@ namespace NadekoBot.Modules.Searches } if (!removed) { - await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); + await channel.SendMessageAsync("❎ No such stream.").ConfigureAwait(false); return; } - await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); + await channel.SendMessageAsync($"πŸ—‘ Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -329,7 +329,7 @@ namespace NadekoBot.Modules.Searches } catch { - await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); + await channel.SendMessageAsync("❎ Stream probably doesn't exist.").ConfigureAwait(false); return; } @@ -340,10 +340,10 @@ namespace NadekoBot.Modules.Searches .Add(stream); await uow.CompleteAsync().ConfigureAwait(false); } - var msg = $"Stream is currently **{(data.IsLive ? "ONLINE" : "OFFLINE")}** with **{data.Views}** viewers"; + var msg = $"ℹ️ Stream is currently **{(data.IsLive ? "ONLINE" : "OFFLINE")}** with **{data.Views}** viewers"; if (data.IsLive) msg += stream.GetLink(); - msg = $":ok: I will notify this channel when status changes.\n{msg}"; + msg = $"πŸ†— I will notify this channel when status changes.\n{msg}"; await channel.SendMessageAsync(msg).ConfigureAwait(false); } } @@ -363,4 +363,4 @@ namespace NadekoBot.Modules.Searches return "???"; } } -} \ No newline at end of file +} From e7fd91b16f6d58233ba444f6b201af0de8ed42de Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 18:53:08 +0530 Subject: [PATCH 02/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 4e0dddf0..4f901a12 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,7 +222,7 @@ namespace NadekoBot.Modules.Utility }, }, - Color = NadekoBot.OkColor + Color = 0x71cd40 }); } From a492302ae173f0a64b39e93c0239720baf308daf Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 19:10:07 +0530 Subject: [PATCH 03/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 4f901a12..c7ac7894 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,7 +222,7 @@ namespace NadekoBot.Modules.Utility }, }, - Color = 0x71cd40 + Color = 0xee281f }); } From 953b014ac603b2761d72cfb91f8a2e82b7080447 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 19:21:52 +0530 Subject: [PATCH 04/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index c7ac7894..028a679b 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,7 +222,7 @@ namespace NadekoBot.Modules.Utility }, }, - Color = 0xee281f + Color = 0x00bbd6 }); } From b9045e916385e137802c97d2ca03a22e32faff9f Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 19:27:45 +0530 Subject: [PATCH 05/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 028a679b..98ebf6c7 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,7 +222,7 @@ namespace NadekoBot.Modules.Utility }, }, - Color = 0x00bbd6 + Color = 0x00bbd6, 0xA8F307 }); } From 783aec9d63acfd2a1c5c16c89725adf8c9ffd958 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 19:31:24 +0530 Subject: [PATCH 06/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 98ebf6c7..847321c0 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,7 +222,8 @@ namespace NadekoBot.Modules.Utility }, }, - Color = 0x00bbd6, 0xA8F307 + Color = 0x00bbd6 + Color = 0xA8F307 }); } From 4a54c548ede2265fcbf690d1e0ec55ccf89d013e Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 19:54:23 +0530 Subject: [PATCH 07/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 847321c0..87504994 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,8 +222,7 @@ namespace NadekoBot.Modules.Utility }, }, - Color = 0x00bbd6 - Color = 0xA8F307 + Color = NadekoBot.InfoColor }); } From 5105602f72785f38e24f3f0344fd2c4a71da57a1 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 19:58:42 +0530 Subject: [PATCH 08/43] Update NadekoBot.cs --- src/NadekoBot/NadekoBot.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index a0d80f36..af00a4ff 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -24,8 +24,12 @@ namespace NadekoBot { private Logger _log; - public static uint OkColor { get; } = 0x00ff00; - public static uint ErrorColor { get; } = 0xff0000; + //public static uint OkColor { get; } = 0x00ff00; + //public static uint ErrorColor { get; } = 0xff0000; + public static uint OkColor { get; } = 0x71cd40; + public static uint ErrorColor { get; } = 0xee281f; + public static uint InfoColor { get; } = 0x00bbd6; + public static uint SunColor { get; } = 0xf1c40f; public static CommandService CommandService { get; private set; } public static CommandHandler CommandHandler { get; private set; } From 7ca781242b1f22a5cd4b5f4f720b8dd3b83d1f6c Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 20:04:44 +0530 Subject: [PATCH 09/43] sun color added to weather --- src/NadekoBot/Modules/Searches/Searches.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 3154e9aa..7f8fefde 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -48,12 +48,12 @@ namespace NadekoBot.Modules.Searches .AddField(fb => fb.WithName("πŸ“ Lat,Long").WithValue($"{obj["latitude"]}, {obj["longitude"]}").WithIsInline(true)) .AddField(fb => fb.WithName("☁ Condition").WithValue($"{obj["condition"]}").WithIsInline(true)) .AddField(fb => fb.WithName("πŸ˜“ Humidity").WithValue($"{obj["humidity"]}%").WithIsInline(true)) - .AddField(fb => fb.WithName("πŸ’¨ Wind Speed").WithValue($"{obj["windspeedk"]}km/h / {obj["windspeedm"]}mph").WithIsInline(true)) - .AddField(fb => fb.WithName("🌑 Temperature").WithValue($"{obj["centigrade"]}Β°C / {obj["fahrenheit"]}Β°F").WithIsInline(true)) + .AddField(fb => fb.WithName("πŸ’¨ Wind Speed").WithValue($"{obj["windspeedk"]}km/h ({obj["windspeedm"]}mph)").WithIsInline(true)) + .AddField(fb => fb.WithName("🌑 Temperature").WithValue($"{obj["centigrade"]}Β°C ({obj["fahrenheit"]}Β°F)").WithIsInline(true)) .AddField(fb => fb.WithName("πŸ”† Feels like").WithValue($"{obj["feelscentigrade"]}Β°C / {obj["feelsfahrenheit"]}Β°F").WithIsInline(true)) .AddField(fb => fb.WithName("πŸŒ„ Sunrise").WithValue($"{obj["sunrise"]}").WithIsInline(true)) .AddField(fb => fb.WithName("πŸŒ‡ Sunset").WithValue($"{obj["sunset"]}").WithIsInline(true)) - .WithColor(NadekoBot.OkColor); + .WithColor(NadekoBot.SunColor); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } From 4bfb75b779caca0d10fdae53ee23b2eb7f303e84 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 20:42:39 +0530 Subject: [PATCH 10/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index b0e1338b..82d27fd0 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -88,16 +88,35 @@ namespace NadekoBot.Modules.Help if (com == null) { - await channel.SendMessageAsync("πŸ” **I can't find that command.**"); + //await channel.SendMessageAsync("πŸ” **I can't find that command.**"); + var erro = new EmbedBuilder() + .WithAuthor(eau => eau.WithName("Help") + .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) + .WithTitle("πŸ”Ž **Error**") + .WithDescription("I can't find that command.") + //.WithThumbnail(tn => tn.Url = NadekoBot.Client.GetCurrentUser().AvatarUrl) + .WithColor(NadekoBot.ErrorColor) + //.WithTimestamp(DateTime.Now); + await channel.EmbedAsync(erro.Build()); return; } - var str = $"**__Help for:__ `{com.Text}`**"; + var str = $"ℹ️ **Command:** `{com.Text}`"; var alias = com.Aliases.Skip(1).FirstOrDefault(); if (alias != null) str += $" / `{alias}`"; + var embed = new EmbedBuilder() + .WithAuthor(eau => eau.WithName("Help") + .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) + .WithTitle(str) + .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") + .AddField(fb => fb.WithIndex(1).WithName("**Usage:**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) + //.WithThumbnail(tn => tn.Url = NadekoBot.Client.GetCurrentUser().AvatarUrl) + .WithColor(NadekoBot.OkColor) + //.WithTimestamp(DateTime.Now); if (com != null) - await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {string.Format(com.Summary, com.Module.Prefix)} {GetCommandRequirements(com)} -**Usage:** {string.Format(com.Remarks, com.Module.Prefix)}").ConfigureAwait(false); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + //await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {string.Format(com.Summary, com.Module.Prefix)} {GetCommandRequirements(com)} +//**Usage:** {string.Format(com.Remarks, com.Module.Prefix)}").ConfigureAwait(false); } private string GetCommandRequirements(Command cmd) From 202561ac7c24523ca6ac8c57240f80f7e78dc4a2 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 20:51:49 +0530 Subject: [PATCH 11/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 82d27fd0..f6334703 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -91,6 +91,7 @@ namespace NadekoBot.Modules.Help //await channel.SendMessageAsync("πŸ” **I can't find that command.**"); var erro = new EmbedBuilder() .WithAuthor(eau => eau.WithName("Help") + .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle("πŸ”Ž **Error**") .WithDescription("I can't find that command.") @@ -106,6 +107,7 @@ namespace NadekoBot.Modules.Help str += $" / `{alias}`"; var embed = new EmbedBuilder() .WithAuthor(eau => eau.WithName("Help") + .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") From 299df813c2be29ebdbe77c970a8f80e78d582dd8 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 20:56:20 +0530 Subject: [PATCH 12/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index f6334703..335e51ac 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -95,9 +95,7 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle("πŸ”Ž **Error**") .WithDescription("I can't find that command.") - //.WithThumbnail(tn => tn.Url = NadekoBot.Client.GetCurrentUser().AvatarUrl) .WithColor(NadekoBot.ErrorColor) - //.WithTimestamp(DateTime.Now); await channel.EmbedAsync(erro.Build()); return; } @@ -112,9 +110,7 @@ namespace NadekoBot.Modules.Help .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") .AddField(fb => fb.WithIndex(1).WithName("**Usage:**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) - //.WithThumbnail(tn => tn.Url = NadekoBot.Client.GetCurrentUser().AvatarUrl) .WithColor(NadekoBot.OkColor) - //.WithTimestamp(DateTime.Now); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); //await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {string.Format(com.Summary, com.Module.Prefix)} {GetCommandRequirements(com)} From 27bf9edb4a4bd3d5d107d16d2db2c58d164fe443 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 21:02:47 +0530 Subject: [PATCH 13/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 335e51ac..55ed751c 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle("πŸ”Ž **Error**") .WithDescription("I can't find that command.") - .WithColor(NadekoBot.ErrorColor) + .WithColor(NadekoBot.ErrorColor); await channel.EmbedAsync(erro.Build()); return; } @@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Help .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") .AddField(fb => fb.WithIndex(1).WithName("**Usage:**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) - .WithColor(NadekoBot.OkColor) + .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); //await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {string.Format(com.Summary, com.Module.Prefix)} {GetCommandRequirements(com)} From c8c237640c1d43a1cd4e26dc4c5c7d6f20750351 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 21:06:53 +0530 Subject: [PATCH 14/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 55ed751c..20fbaee0 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Help //await channel.SendMessageAsync("πŸ” **I can't find that command.**"); var erro = new EmbedBuilder() .WithAuthor(eau => eau.WithName("Help") - .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") + .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/")) .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle("πŸ”Ž **Error**") .WithDescription("I can't find that command.") @@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Help str += $" / `{alias}`"; var embed = new EmbedBuilder() .WithAuthor(eau => eau.WithName("Help") - .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") + .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/")) .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") From fdba24c27caed0c035928a17c1d7bdeee7a6f301 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 21:08:22 +0530 Subject: [PATCH 15/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 20fbaee0..aab284d0 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Help //await channel.SendMessageAsync("πŸ” **I can't find that command.**"); var erro = new EmbedBuilder() .WithAuthor(eau => eau.WithName("Help") - .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/")) + .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle("πŸ”Ž **Error**") .WithDescription("I can't find that command.") @@ -105,7 +105,7 @@ namespace NadekoBot.Modules.Help str += $" / `{alias}`"; var embed = new EmbedBuilder() .WithAuthor(eau => eau.WithName("Help") - .WithAuthor(eau => eau.WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/")) + .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") From 27d576b0f3b0c84991c85e2a17f94972e89387ab Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 21:19:04 +0530 Subject: [PATCH 16/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index aab284d0..ac3ab9f8 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -93,13 +93,13 @@ namespace NadekoBot.Modules.Help .WithAuthor(eau => eau.WithName("Help") .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) - .WithTitle("πŸ”Ž **Error**") + .WithTitle("πŸ”Ž **Sorry!**") .WithDescription("I can't find that command.") .WithColor(NadekoBot.ErrorColor); await channel.EmbedAsync(erro.Build()); return; } - var str = $"ℹ️ **Command:** `{com.Text}`"; + var str = $"ℹ️ **Command:** `{com.Text}`"; var alias = com.Aliases.Skip(1).FirstOrDefault(); if (alias != null) str += $" / `{alias}`"; @@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(1).WithName("**Usage:**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) + .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From 29c9b8f6dd06dee4f29927165a3771a5b4bc3fdd Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 21:31:30 +0530 Subject: [PATCH 17/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index ac3ab9f8..a6306da1 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -93,13 +93,13 @@ namespace NadekoBot.Modules.Help .WithAuthor(eau => eau.WithName("Help") .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) - .WithTitle("πŸ”Ž **Sorry!**") - .WithDescription("I can't find that command.") + .WithTitle("πŸ” **Sorry!**") + .WithDescription("I can't find that command. Please check the **command** and **command prefix** before trying again.") .WithColor(NadekoBot.ErrorColor); await channel.EmbedAsync(erro.Build()); return; } - var str = $"ℹ️ **Command:** `{com.Text}`"; + var str = $"ℹ️ **Command:** `{com.Text}`"; var alias = com.Aliases.Skip(1).FirstOrDefault(); if (alias != null) str += $" / `{alias}`"; From b73c7599ec2310079f9054dda7b6118f0a630a89 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 21:44:56 +0530 Subject: [PATCH 18/43] Update Searches.cs --- src/NadekoBot/Modules/Searches/Searches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 7f8fefde..73c996b9 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Searches .AddField(fb => fb.WithName("πŸ˜“ Humidity").WithValue($"{obj["humidity"]}%").WithIsInline(true)) .AddField(fb => fb.WithName("πŸ’¨ Wind Speed").WithValue($"{obj["windspeedk"]}km/h ({obj["windspeedm"]}mph)").WithIsInline(true)) .AddField(fb => fb.WithName("🌑 Temperature").WithValue($"{obj["centigrade"]}Β°C ({obj["fahrenheit"]}Β°F)").WithIsInline(true)) - .AddField(fb => fb.WithName("πŸ”† Feels like").WithValue($"{obj["feelscentigrade"]}Β°C / {obj["feelsfahrenheit"]}Β°F").WithIsInline(true)) + .AddField(fb => fb.WithName("πŸ”† Feels like").WithValue($"{obj["feelscentigrade"]}Β°C ({obj["feelsfahrenheit"]}Β°F)").WithIsInline(true)) .AddField(fb => fb.WithName("πŸŒ„ Sunrise").WithValue($"{obj["sunrise"]}").WithIsInline(true)) .AddField(fb => fb.WithName("πŸŒ‡ Sunset").WithValue($"{obj["sunset"]}").WithIsInline(true)) .WithColor(NadekoBot.SunColor); From 6e00fdee51c9b4c49ec9b7acd284cdba328a751a Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 23:18:59 +0530 Subject: [PATCH 19/43] Update NadekoBot.cs --- src/NadekoBot/NadekoBot.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index af00a4ff..b6342b48 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -28,8 +28,6 @@ namespace NadekoBot //public static uint ErrorColor { get; } = 0xff0000; public static uint OkColor { get; } = 0x71cd40; public static uint ErrorColor { get; } = 0xee281f; - public static uint InfoColor { get; } = 0x00bbd6; - public static uint SunColor { get; } = 0xf1c40f; public static CommandService CommandService { get; private set; } public static CommandHandler CommandHandler { get; private set; } From b37dd86e6efe7c6be7352bca15dc75901c8d0db6 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 23:20:51 +0530 Subject: [PATCH 20/43] Update Searches.cs --- src/NadekoBot/Modules/Searches/Searches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 73c996b9..5cb42f5a 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Searches .AddField(fb => fb.WithName("πŸ”† Feels like").WithValue($"{obj["feelscentigrade"]}Β°C ({obj["feelsfahrenheit"]}Β°F)").WithIsInline(true)) .AddField(fb => fb.WithName("πŸŒ„ Sunrise").WithValue($"{obj["sunrise"]}").WithIsInline(true)) .AddField(fb => fb.WithName("πŸŒ‡ Sunset").WithValue($"{obj["sunset"]}").WithIsInline(true)) - .WithColor(NadekoBot.SunColor); + .WithColor(NadekoBot.OkColor); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } From 9ed3e7fd04e5c9f46b5b7d6c7cfd8d36efb59e87 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 23:22:26 +0530 Subject: [PATCH 21/43] Update Utility.cs --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 87504994..028a679b 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -222,7 +222,7 @@ namespace NadekoBot.Modules.Utility }, }, - Color = NadekoBot.InfoColor + Color = 0x00bbd6 }); } From 395b27f138e070a9f9ad2d83ab563ea2e8c3a53e Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 23:24:56 +0530 Subject: [PATCH 22/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index a6306da1..a6f56c69 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -93,13 +93,13 @@ namespace NadekoBot.Modules.Help .WithAuthor(eau => eau.WithName("Help") .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) - .WithTitle("πŸ” **Sorry!**") + .WithTitle("**Sorry!**") .WithDescription("I can't find that command. Please check the **command** and **command prefix** before trying again.") .WithColor(NadekoBot.ErrorColor); await channel.EmbedAsync(erro.Build()); return; } - var str = $"ℹ️ **Command:** `{com.Text}`"; + var str = $"**Command:** `{com.Text}`"; var alias = com.Aliases.Skip(1).FirstOrDefault(); if (alias != null) str += $" / `{alias}`"; From a24577af48ab2add86d257d8a799a0462bd88f2e Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 23:40:14 +0530 Subject: [PATCH 23/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index a6f56c69..546d8c91 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -93,13 +93,13 @@ namespace NadekoBot.Modules.Help .WithAuthor(eau => eau.WithName("Help") .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) - .WithTitle("**Sorry!**") + .WithTitle("Sorry!") .WithDescription("I can't find that command. Please check the **command** and **command prefix** before trying again.") .WithColor(NadekoBot.ErrorColor); await channel.EmbedAsync(erro.Build()); return; } - var str = $"**Command:** `{com.Text}`"; + var str = $"Command: {com.Text}"; var alias = com.Aliases.Skip(1).FirstOrDefault(); if (alias != null) str += $" / `{alias}`"; From 55e66fbe443780257297b4f942d862664d49632d Mon Sep 17 00:00:00 2001 From: samvaio Date: Sat, 3 Dec 2016 23:57:59 +0530 Subject: [PATCH 24/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 546d8c91..d42e39ec 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -109,7 +109,8 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) + .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false) + .WithIndex(2).WithName("**TEST**").WithValue($"Testing").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From 2a65e5686146cab33ffb2e5739b8bffe4e394170 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:03:37 +0530 Subject: [PATCH 25/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index d42e39ec..fd890a31 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false) + .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) .WithIndex(2).WithName("**TEST**").WithValue($"Testing").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) From e90c0f3ae8c980025ebbae89e833490c65afbd5b Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:12:14 +0530 Subject: [PATCH 26/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index fd890a31..86aa6a53 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -109,8 +109,8 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) - .WithIndex(2).WithName("**TEST**").WithValue($"Testing").WithIsInline(true)) + .AddField(fb => fb.WithIndex(2).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) + .WithIndex(1).WithName("**TEST**").WithValue($"Testing").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From 04b937bb850d06946646687093ed6c6304b0fb82 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:18:56 +0530 Subject: [PATCH 27/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 86aa6a53..e5b0523b 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -109,8 +109,10 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(2).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) - .WithIndex(1).WithName("**TEST**").WithValue($"Testing").WithIsInline(true)) + .AddField(fb => fb.WithIndex().WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) + .WithName("**TEST1**").WithValue($"Testing1").WithIsInline(true) + .WithName("**TEST2**").WithValue($"Testing2").WithIsInline(true) + .WithName("**TEST3**").WithValue($"Testing3").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From 1bf6fe34a5f5fcc9a1a0746033c6579eb01613e9 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:22:15 +0530 Subject: [PATCH 28/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index e5b0523b..b311178d 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) .WithTitle(str) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex().WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) + .AddField(fb => fb.WithIndex(4).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) .WithName("**TEST1**").WithValue($"Testing1").WithIsInline(true) .WithName("**TEST2**").WithValue($"Testing2").WithIsInline(true) .WithName("**TEST3**").WithValue($"Testing3").WithIsInline(true)) From efc0107a14e3390399f0b0c606ff3beed4f8be3a Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:32:15 +0530 Subject: [PATCH 29/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index b311178d..cfeb881f 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -99,7 +99,7 @@ namespace NadekoBot.Modules.Help await channel.EmbedAsync(erro.Build()); return; } - var str = $"Command: {com.Text}"; + var str = $"{com.Text}"; var alias = com.Aliases.Skip(1).FirstOrDefault(); if (alias != null) str += $" / `{alias}`"; @@ -107,12 +107,13 @@ namespace NadekoBot.Modules.Help .WithAuthor(eau => eau.WithName("Help") .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) - .WithTitle(str) + //.WithTitle(str) + .AddField(fb => fb.WithName("**Command**").WithValue(str).WithIsInline(true)) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(4).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) - .WithName("**TEST1**").WithValue($"Testing1").WithIsInline(true) - .WithName("**TEST2**").WithValue($"Testing2").WithIsInline(true) - .WithName("**TEST3**").WithValue($"Testing3").WithIsInline(true)) + .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) + //.WithName("**TEST1**").WithValue($"Testing1").WithIsInline(true) + //.WithName("**TEST2**").WithValue($"Testing2").WithIsInline(true) + //.WithName("**TEST3**").WithValue($"Testing3").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From 64169ab8f3a7a51ab2a1eb9eeb751d9bfa9a2cb8 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:33:49 +0530 Subject: [PATCH 30/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index cfeb881f..62247117 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -108,9 +108,9 @@ namespace NadekoBot.Modules.Help .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) //.WithTitle(str) - .AddField(fb => fb.WithName("**Command**").WithValue(str).WithIsInline(true)) + .AddField(fb => fb.WithIndex(1).WithName("**Command**").WithValue(str).WithIsInline(true)) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(1).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true) + .AddField(fb => fb.WithIndex(3).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) //.WithName("**TEST1**").WithValue($"Testing1").WithIsInline(true) //.WithName("**TEST2**").WithValue($"Testing2").WithIsInline(true) //.WithName("**TEST3**").WithValue($"Testing3").WithIsInline(true)) From ad3cd193255fe37dcb65a1d526475699575a236f Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:39:41 +0530 Subject: [PATCH 31/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 62247117..79dc9ec8 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -110,10 +110,8 @@ namespace NadekoBot.Modules.Help //.WithTitle(str) .AddField(fb => fb.WithIndex(1).WithName("**Command**").WithValue(str).WithIsInline(true)) .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") + .AddField(fb => fb.WithIndex(2).WithName("TEST").WithValue($"TESTING1").WithIsInline(false)) .AddField(fb => fb.WithIndex(3).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) - //.WithName("**TEST1**").WithValue($"Testing1").WithIsInline(true) - //.WithName("**TEST2**").WithValue($"Testing2").WithIsInline(true) - //.WithName("**TEST3**").WithValue($"Testing3").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From a33ae7114c17f1d098d2de60931427bb0ea4c87d Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:46:53 +0530 Subject: [PATCH 32/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 79dc9ec8..54b4352f 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -109,9 +109,9 @@ namespace NadekoBot.Modules.Help .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) //.WithTitle(str) .AddField(fb => fb.WithIndex(1).WithName("**Command**").WithValue(str).WithIsInline(true)) - .WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(2).WithName("TEST").WithValue($"TESTING1").WithIsInline(false)) - .AddField(fb => fb.WithIndex(3).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(false)) + //.WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") + .AddField(fb => fb.WithIndex(2).WithName("TEST").WithValue($"TESTING1").WithIsInline(true)) + .AddField(fb => fb.WithIndex(3).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From 1691970dbc0ffcc4638b6d3287ea7d163de07d5c Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 00:54:04 +0530 Subject: [PATCH 33/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 54b4352f..6116c97f 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -108,10 +108,10 @@ namespace NadekoBot.Modules.Help .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) //.WithTitle(str) - .AddField(fb => fb.WithIndex(1).WithName("**Command**").WithValue(str).WithIsInline(true)) //.WithDescription($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}") - .AddField(fb => fb.WithIndex(2).WithName("TEST").WithValue($"TESTING1").WithIsInline(true)) - .AddField(fb => fb.WithIndex(3).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true)) + .AddField(fb => fb.WithIndex(1).WithName("**Command**").WithValue(str).WithIsInline(true)) + .AddField(fb => fb.WithIndex(2).WithName("**Usage**").WithValue($"{string.Format(com.Remarks, com.Module.Prefix)}").WithIsInline(true)) + .AddField(fb => fb.WithIndex(3).WithName("Description").WithValue($"{ string.Format(com.Summary, com.Module.Prefix)}{ GetCommandRequirements(com)}").WithIsInline(false)) .WithColor(NadekoBot.OkColor); if (com != null) await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); From fbfa3e1042575f470cbac8cbc44b6d26890129bb Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:20:26 +0530 Subject: [PATCH 34/43] Update Help.cs --- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 6116c97f..73f10f05 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -90,10 +90,10 @@ namespace NadekoBot.Modules.Help { //await channel.SendMessageAsync("πŸ” **I can't find that command.**"); var erro = new EmbedBuilder() - .WithAuthor(eau => eau.WithName("Help") + .WithAuthor(eau => eau.WithName("Sorry!") .WithUrl("http://nadekobot.readthedocs.io/en/latest/Commands%20List/") .WithIconUrl(NadekoBot.Client.GetCurrentUser().AvatarUrl)) - .WithTitle("Sorry!") + //.WithTitle("Sorry!") .WithDescription("I can't find that command. Please check the **command** and **command prefix** before trying again.") .WithColor(NadekoBot.ErrorColor); await channel.EmbedAsync(erro.Build()); From 46d9fc234cd05b72ede167ff61cc1e55a52bfb6b Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:23:17 +0530 Subject: [PATCH 35/43] Delete StreamNotificationCommands.cs --- .../Commands/StreamNotificationCommands.cs | 367 ------------------ 1 file changed, 367 deletions(-) delete mode 100644 src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs deleted file mode 100644 index 38e89a8b..00000000 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ /dev/null @@ -1,367 +0,0 @@ -ο»Ώusing Discord.Commands; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Threading.Tasks; -using Discord; -using NadekoBot.Services; -using System.Threading; -using System.Collections.Generic; -using NadekoBot.Services.Database.Models; -using System.Net.Http; -using Discord.WebSocket; -using NadekoBot.Attributes; -using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using NLog; -using NadekoBot.Services.Database; -using NadekoBot.Extensions; - -namespace NadekoBot.Modules.Searches -{ - public partial class Searches - { - public class StreamStatus - { - public bool IsLive { get; set; } - public string ApiLink { get; set; } - public string Views { get; set; } - } - - public class HitboxResponse { - public bool Success { get; set; } = true; - [JsonProperty("media_is_live")] - public string MediaIsLive { get; set; } - public bool IsLive => MediaIsLive == "1"; - [JsonProperty("media_views")] - public string Views { get; set; } - } - - public class TwitchResponse - { - public string Error { get; set; } = null; - public bool IsLive => Stream != null; - public StreamInfo Stream { get; set; } - - public class StreamInfo - { - public int Viewers { get; set; } - } - } - - public class BeamResponse - { - public string Error { get; set; } = null; - - [JsonProperty("online")] - public bool IsLive { get; set; } - public int ViewersCurrent { get; set; } - } - - public class StreamNotFoundException : Exception - { - public StreamNotFoundException(string message) : base("Stream '" + message + "' not found.") - { - } - } - - [Group] - public class StreamNotificationCommands - { - private Timer checkTimer { get; } - private ConcurrentDictionary oldCachedStatuses = new ConcurrentDictionary(); - private ConcurrentDictionary cachedStatuses = new ConcurrentDictionary(); - private Logger _log { get; } - - private bool FirstPass { get; set; } = true; - - public StreamNotificationCommands() - { - - _log = NLog.LogManager.GetCurrentClassLogger(); - checkTimer = new Timer(async (state) => - { - oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); - cachedStatuses.Clear(); - IEnumerable streams; - using (var uow = DbHandler.UnitOfWork()) - { - streams = uow.GuildConfigs.GetAllFollowedStreams(); - } - - await Task.WhenAll(streams.Select(async fs => - { - try - { - var newStatus = await GetStreamStatus(fs).ConfigureAwait(false); - if (FirstPass) - { - return; - } - - StreamStatus oldStatus; - if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) && - oldStatus.IsLive != newStatus.IsLive) - { - var msg = $"`{fs.Username}`'s stream is now " + - $"**{(newStatus.IsLive ? "ONLINE" : "OFFLINE")}** with " + - $"**{newStatus.Views}** viewers."; - - var server = NadekoBot.Client.GetGuild(fs.GuildId); - var channel = server?.GetTextChannel(fs.ChannelId); - if (channel == null) - return; - if (newStatus.IsLive) - msg += "\n" + fs.GetLink(); - try { await channel.SendMessageAsync(msg).ConfigureAwait(false); } catch { } - } - } - catch (Exception ex) - { - - } - })); - - FirstPass = false; - }, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); - } - - private async Task GetStreamStatus(FollowedStream stream, bool checkCache = true) - { - string response; - StreamStatus result; - switch (stream.Type) - { - case FollowedStream.FollowedStreamType.Hitbox: - var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username}"; - if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false); - } - var hbData = JsonConvert.DeserializeObject(response); - if (!hbData.Success) - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - result = new StreamStatus() - { - IsLive = hbData.IsLive, - ApiLink = hitboxUrl, - Views = hbData.Views - }; - cachedStatuses.AddOrUpdate(hitboxUrl, result, (key, old) => result); - return result; - case FollowedStream.FollowedStreamType.Twitch: - var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6"; - if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false); - } - var twData = JsonConvert.DeserializeObject(response); - if (twData.Error != null) - { - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - } - result = new StreamStatus() - { - IsLive = twData.IsLive, - ApiLink = twitchUrl, - Views = twData.Stream?.Viewers.ToString() ?? "0" - }; - cachedStatuses.AddOrUpdate(twitchUrl, result, (key, old) => result); - return result; - case FollowedStream.FollowedStreamType.Beam: - var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username}"; - if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(beamUrl).ConfigureAwait(false); - } - - var bmData = JsonConvert.DeserializeObject(response); - if (bmData.Error != null) - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - result = new StreamStatus() - { - IsLive = bmData.IsLive, - ApiLink = beamUrl, - Views = bmData.ViewersCurrent.ToString() - }; - cachedStatuses.AddOrUpdate(beamUrl, result, (key, old) => result); - return result; - default: - break; - } - return null; - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Hitbox(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Twitch(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Beam(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task ListStreams(IUserMessage imsg) - { - var channel = (ITextChannel)imsg.Channel; - - IEnumerable streams; - using (var uow = DbHandler.UnitOfWork()) - { - streams = uow.GuildConfigs - .For(channel.Guild.Id, - set => set.Include(gc => gc.FollowedStreams)) - .FollowedStreams; - } - - if (!streams.Any()) - { - await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); - return; - } - - var text = string.Join("\n", streams.Select(snc => - { - return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】"; - })); - - await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false); - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task RemoveStream(IUserMessage msg, FollowedStream.FollowedStreamType type, [Remainder] string username) - { - var channel = (ITextChannel)msg.Channel; - - username = username.ToLowerInvariant().Trim(); - - var fs = new FollowedStream() - { - ChannelId = channel.Id, - Username = username, - Type = type - }; - - bool removed; - using (var uow = DbHandler.UnitOfWork()) - { - var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)); - removed = config.FollowedStreams.Remove(fs); - if (removed) - await uow.CompleteAsync().ConfigureAwait(false); - } - if (!removed) - { - await channel.SendMessageAsync("❎ No such stream.").ConfigureAwait(false); - return; - } - await channel.SendMessageAsync($"πŸ—‘ Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) - { - var channel = (ITextChannel)imsg.Channel; - - var stream = username?.Trim(); - if (string.IsNullOrWhiteSpace(stream)) - return; - try - { - var streamStatus = (await GetStreamStatus(new FollowedStream - { - Username = stream, - Type = platform, - })); - if (streamStatus.IsLive) - { - await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`"); - } - else - { - await channel.SendMessageAsync($"`Streamer {username} is offline.`"); - } - } - catch - { - await channel.SendMessageAsync("No channel found."); - } - } - - private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) - { - username = username.ToLowerInvariant().Trim(); - var stream = new FollowedStream - { - GuildId = channel.Guild.Id, - ChannelId = channel.Id, - Username = username, - Type = type, - }; - - StreamStatus data; - try - { - data = await GetStreamStatus(stream).ConfigureAwait(false); - } - catch - { - await channel.SendMessageAsync("❎ Stream probably doesn't exist.").ConfigureAwait(false); - return; - } - - using (var uow = DbHandler.UnitOfWork()) - { - uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) - .FollowedStreams - .Add(stream); - await uow.CompleteAsync().ConfigureAwait(false); - } - var msg = $"ℹ️ Stream is currently **{(data.IsLive ? "ONLINE" : "OFFLINE")}** with **{data.Views}** viewers"; - if (data.IsLive) - msg += stream.GetLink(); - msg = $"πŸ†— I will notify this channel when status changes.\n{msg}"; - await channel.SendMessageAsync(msg).ConfigureAwait(false); - } - } - } - - public static class FollowedStreamExtensions - { - public static string GetLink(this FollowedStream fs) - { - //todo C#7 - if (fs.Type == FollowedStream.FollowedStreamType.Hitbox) - return $"\n`Here is the Link:`【 http://www.hitbox.tv/{fs.Username}/ 】"; - else if (fs.Type == FollowedStream.FollowedStreamType.Twitch) - return $"\n`Here is the Link:`【 http://www.twitch.tv/{fs.Username}/ 】"; - else if (fs.Type == FollowedStream.FollowedStreamType.Beam) - return $"\n`Here is the Link:`【 https://beam.pro/{fs.Username}/ 】"; - return "???"; - } - } -} From 76a58fb2b4a95da81422059c9fe126c164988c31 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:23:53 +0530 Subject: [PATCH 36/43] reverted --- .../Commands/StreamNotificationCommands.cs | 410 ++++++++++++++++++ 1 file changed, 410 insertions(+) create mode 100644 src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs new file mode 100644 index 00000000..e038a9d8 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -0,0 +1,410 @@ +ο»Ώusing Discord.Commands; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Concurrent; +using System.Linq; +using System.Threading.Tasks; +using Discord; +using NadekoBot.Services; +using System.Threading; +using System.Collections.Generic; +using NadekoBot.Services.Database.Models; +using System.Net.Http; +using Discord.WebSocket; +using NadekoBot.Attributes; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using NLog; +using NadekoBot.Services.Database; +using NadekoBot.Extensions; + +namespace NadekoBot.Modules.Searches +{ + public partial class Searches + { + public class StreamStatus + { + public bool IsLive { get; set; } + public string ApiLink { get; set; } + public string Views { get; set; } + } + + public class HitboxResponse { + public bool Success { get; set; } = true; + [JsonProperty("media_is_live")] + public string MediaIsLive { get; set; } + public bool IsLive => MediaIsLive == "1"; + [JsonProperty("media_views")] + public string Views { get; set; } + } + + public class TwitchResponse + { + public string Error { get; set; } = null; + public bool IsLive => Stream != null; + public StreamInfo Stream { get; set; } + + public class StreamInfo + { + public int Viewers { get; set; } + } + } + + public class BeamResponse + { + public string Error { get; set; } = null; + + [JsonProperty("online")] + public bool IsLive { get; set; } + public int ViewersCurrent { get; set; } + } + + public class StreamNotFoundException : Exception + { + public StreamNotFoundException(string message) : base("Stream '" + message + "' not found.") + { + } + } + + [Group] + public class StreamNotificationCommands + { + private Timer checkTimer { get; } + private ConcurrentDictionary oldCachedStatuses = new ConcurrentDictionary(); + private ConcurrentDictionary cachedStatuses = new ConcurrentDictionary(); + private Logger _log { get; } + + private bool FirstPass { get; set; } = true; + + public StreamNotificationCommands() + { + + _log = NLog.LogManager.GetCurrentClassLogger(); + checkTimer = new Timer(async (state) => + { + oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); + cachedStatuses.Clear(); + IEnumerable streams; + using (var uow = DbHandler.UnitOfWork()) + { + streams = uow.GuildConfigs.GetAllFollowedStreams(); + } + + await Task.WhenAll(streams.Select(async fs => + { + try + { + var newStatus = await GetStreamStatus(fs).ConfigureAwait(false); + if (FirstPass) + { + return; + } + + StreamStatus oldStatus; + if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) && + oldStatus.IsLive != newStatus.IsLive) + { + var server = NadekoBot.Client.GetGuild(fs.GuildId); + var channel = server?.GetTextChannel(fs.ChannelId); + if (channel == null) + return; + try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { } + } + } + catch (Exception ex) + { + + } + })); + + FirstPass = false; + }, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); + } + + private async Task GetStreamStatus(FollowedStream stream, bool checkCache = true) + { + string response; + StreamStatus result; + switch (stream.Type) + { + case FollowedStream.FollowedStreamType.Hitbox: + var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username.ToLowerInvariant()}"; + if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false); + } + var hbData = JsonConvert.DeserializeObject(response); + if (!hbData.Success) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + result = new StreamStatus() + { + IsLive = hbData.IsLive, + ApiLink = hitboxUrl, + Views = hbData.Views + }; + cachedStatuses.AddOrUpdate(hitboxUrl, result, (key, old) => result); + return result; + case FollowedStream.FollowedStreamType.Twitch: + var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username.ToLowerInvariant())}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6"; + if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false); + } + var twData = JsonConvert.DeserializeObject(response); + if (twData.Error != null) + { + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + } + result = new StreamStatus() + { + IsLive = twData.IsLive, + ApiLink = twitchUrl, + Views = twData.Stream?.Viewers.ToString() ?? "0" + }; + cachedStatuses.AddOrUpdate(twitchUrl, result, (key, old) => result); + return result; + case FollowedStream.FollowedStreamType.Beam: + var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username.ToLowerInvariant()}"; + if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(beamUrl).ConfigureAwait(false); + } + + var bmData = JsonConvert.DeserializeObject(response); + if (bmData.Error != null) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + result = new StreamStatus() + { + IsLive = bmData.IsLive, + ApiLink = beamUrl, + Views = bmData.ViewersCurrent.ToString() + }; + cachedStatuses.AddOrUpdate(beamUrl, result, (key, old) => result); + return result; + default: + break; + } + return null; + } + + //[NadekoCommand, Usage, Description, Aliases] + //[RequireContext(ContextType.Guild)] + //public async Task Test(IUserMessage imsg) + //{ + // var channel = (ITextChannel)imsg.Channel; + + // await channel.EmbedAsync(new Discord.API.Embed() + // { + // Title = "Imqtpie", + // Url = "https://twitch.tv/masterkwoth", + // Fields = new[] { + // new Discord.API.EmbedField() + // { + // Name = "Status", + // Value = "Online", + // Inline = true, + // }, + // new Discord.API.EmbedField() + // { + // Name = "Viewers", + // Value = "123123", + // Inline = true + // }, + // new Discord.API.EmbedField() + // { + // Name = "Platform", + // Value = "Twitch", + // Inline = true + // }, + // }, + // Color = NadekoBot.OkColor + // }); + //} + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Hitbox(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Twitch(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Beam(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task ListStreams(IUserMessage imsg) + { + var channel = (ITextChannel)imsg.Channel; + + IEnumerable streams; + using (var uow = DbHandler.UnitOfWork()) + { + streams = uow.GuildConfigs + .For(channel.Guild.Id, + set => set.Include(gc => gc.FollowedStreams)) + .FollowedStreams; + } + + if (!streams.Any()) + { + await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); + return; + } + + var text = string.Join("\n", streams.Select(snc => + { + return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】"; + })); + + await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task RemoveStream(IUserMessage msg, FollowedStream.FollowedStreamType type, [Remainder] string username) + { + var channel = (ITextChannel)msg.Channel; + + username = username.ToLowerInvariant().Trim(); + + var fs = new FollowedStream() + { + ChannelId = channel.Id, + Username = username, + Type = type + }; + + bool removed; + using (var uow = DbHandler.UnitOfWork()) + { + var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)); + removed = config.FollowedStreams.Remove(fs); + if (removed) + await uow.CompleteAsync().ConfigureAwait(false); + } + if (!removed) + { + await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); + return; + } + await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) + { + var channel = (ITextChannel)imsg.Channel; + + var stream = username?.Trim(); + if (string.IsNullOrWhiteSpace(stream)) + return; + try + { + var streamStatus = (await GetStreamStatus(new FollowedStream + { + Username = stream, + Type = platform, + })); + if (streamStatus.IsLive) + { + await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`"); + } + else + { + await channel.SendMessageAsync($"`Streamer {username} is offline.`"); + } + } + catch + { + await channel.SendMessageAsync("No channel found."); + } + } + + private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) + { + username = username.Trim(); + var fs = new FollowedStream + { + GuildId = channel.Guild.Id, + ChannelId = channel.Id, + Username = username, + Type = type, + }; + + StreamStatus status; + try + { + status = await GetStreamStatus(fs).ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); + return; + } + + using (var uow = DbHandler.UnitOfWork()) + { + uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) + .FollowedStreams + .Add(fs); + await uow.CompleteAsync().ConfigureAwait(false); + } + + var msg = $":ok: I will notify this channel when status changes."; + await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); + } + } + } + + public static class FollowedStreamExtensions + { + public static EmbedBuilder GetEmbed(this FollowedStream fs, Searches.StreamStatus status) + { + var embed = new EmbedBuilder().WithTitle(fs.Username) + .WithUrl(fs.GetLink()) + .AddField(efb => efb.WithName("Status") + .WithValue(status.IsLive ? "Online" : "Offline") + .WithIsInline(true)) + .AddField(efb => efb.WithName("Viewers") + .WithValue(status.IsLive ? status.Views : "-") + .WithIsInline(true)) + .AddField(efb => efb.WithName("Platform") + .WithValue(fs.Type.ToString()) + .WithIsInline(true)) + .WithColor(status.IsLive ? NadekoBot.OkColor : NadekoBot.ErrorColor); + + return embed; + } + + public static string GetLink(this FollowedStream fs) { + if (fs.Type == FollowedStream.FollowedStreamType.Hitbox) + return $"http://www.hitbox.tv/{fs.Username}/"; + else if (fs.Type == FollowedStream.FollowedStreamType.Twitch) + return $"http://www.twitch.tv/{fs.Username}/"; + else if (fs.Type == FollowedStream.FollowedStreamType.Beam) + return $"https://beam.pro/{fs.Username}/"; + else + return "??"; + } + } +} \ No newline at end of file From e62bdb916d5a1dfc04ee49a4920bd509c1b017a3 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:32:30 +0530 Subject: [PATCH 37/43] Delete StreamNotificationCommands.cs --- .../Commands/StreamNotificationCommands.cs | 410 ------------------ 1 file changed, 410 deletions(-) delete mode 100644 src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs deleted file mode 100644 index e038a9d8..00000000 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ /dev/null @@ -1,410 +0,0 @@ -ο»Ώusing Discord.Commands; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Threading.Tasks; -using Discord; -using NadekoBot.Services; -using System.Threading; -using System.Collections.Generic; -using NadekoBot.Services.Database.Models; -using System.Net.Http; -using Discord.WebSocket; -using NadekoBot.Attributes; -using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using NLog; -using NadekoBot.Services.Database; -using NadekoBot.Extensions; - -namespace NadekoBot.Modules.Searches -{ - public partial class Searches - { - public class StreamStatus - { - public bool IsLive { get; set; } - public string ApiLink { get; set; } - public string Views { get; set; } - } - - public class HitboxResponse { - public bool Success { get; set; } = true; - [JsonProperty("media_is_live")] - public string MediaIsLive { get; set; } - public bool IsLive => MediaIsLive == "1"; - [JsonProperty("media_views")] - public string Views { get; set; } - } - - public class TwitchResponse - { - public string Error { get; set; } = null; - public bool IsLive => Stream != null; - public StreamInfo Stream { get; set; } - - public class StreamInfo - { - public int Viewers { get; set; } - } - } - - public class BeamResponse - { - public string Error { get; set; } = null; - - [JsonProperty("online")] - public bool IsLive { get; set; } - public int ViewersCurrent { get; set; } - } - - public class StreamNotFoundException : Exception - { - public StreamNotFoundException(string message) : base("Stream '" + message + "' not found.") - { - } - } - - [Group] - public class StreamNotificationCommands - { - private Timer checkTimer { get; } - private ConcurrentDictionary oldCachedStatuses = new ConcurrentDictionary(); - private ConcurrentDictionary cachedStatuses = new ConcurrentDictionary(); - private Logger _log { get; } - - private bool FirstPass { get; set; } = true; - - public StreamNotificationCommands() - { - - _log = NLog.LogManager.GetCurrentClassLogger(); - checkTimer = new Timer(async (state) => - { - oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); - cachedStatuses.Clear(); - IEnumerable streams; - using (var uow = DbHandler.UnitOfWork()) - { - streams = uow.GuildConfigs.GetAllFollowedStreams(); - } - - await Task.WhenAll(streams.Select(async fs => - { - try - { - var newStatus = await GetStreamStatus(fs).ConfigureAwait(false); - if (FirstPass) - { - return; - } - - StreamStatus oldStatus; - if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) && - oldStatus.IsLive != newStatus.IsLive) - { - var server = NadekoBot.Client.GetGuild(fs.GuildId); - var channel = server?.GetTextChannel(fs.ChannelId); - if (channel == null) - return; - try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { } - } - } - catch (Exception ex) - { - - } - })); - - FirstPass = false; - }, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); - } - - private async Task GetStreamStatus(FollowedStream stream, bool checkCache = true) - { - string response; - StreamStatus result; - switch (stream.Type) - { - case FollowedStream.FollowedStreamType.Hitbox: - var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username.ToLowerInvariant()}"; - if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false); - } - var hbData = JsonConvert.DeserializeObject(response); - if (!hbData.Success) - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - result = new StreamStatus() - { - IsLive = hbData.IsLive, - ApiLink = hitboxUrl, - Views = hbData.Views - }; - cachedStatuses.AddOrUpdate(hitboxUrl, result, (key, old) => result); - return result; - case FollowedStream.FollowedStreamType.Twitch: - var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username.ToLowerInvariant())}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6"; - if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false); - } - var twData = JsonConvert.DeserializeObject(response); - if (twData.Error != null) - { - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - } - result = new StreamStatus() - { - IsLive = twData.IsLive, - ApiLink = twitchUrl, - Views = twData.Stream?.Viewers.ToString() ?? "0" - }; - cachedStatuses.AddOrUpdate(twitchUrl, result, (key, old) => result); - return result; - case FollowedStream.FollowedStreamType.Beam: - var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username.ToLowerInvariant()}"; - if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(beamUrl).ConfigureAwait(false); - } - - var bmData = JsonConvert.DeserializeObject(response); - if (bmData.Error != null) - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - result = new StreamStatus() - { - IsLive = bmData.IsLive, - ApiLink = beamUrl, - Views = bmData.ViewersCurrent.ToString() - }; - cachedStatuses.AddOrUpdate(beamUrl, result, (key, old) => result); - return result; - default: - break; - } - return null; - } - - //[NadekoCommand, Usage, Description, Aliases] - //[RequireContext(ContextType.Guild)] - //public async Task Test(IUserMessage imsg) - //{ - // var channel = (ITextChannel)imsg.Channel; - - // await channel.EmbedAsync(new Discord.API.Embed() - // { - // Title = "Imqtpie", - // Url = "https://twitch.tv/masterkwoth", - // Fields = new[] { - // new Discord.API.EmbedField() - // { - // Name = "Status", - // Value = "Online", - // Inline = true, - // }, - // new Discord.API.EmbedField() - // { - // Name = "Viewers", - // Value = "123123", - // Inline = true - // }, - // new Discord.API.EmbedField() - // { - // Name = "Platform", - // Value = "Twitch", - // Inline = true - // }, - // }, - // Color = NadekoBot.OkColor - // }); - //} - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Hitbox(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Twitch(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Beam(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task ListStreams(IUserMessage imsg) - { - var channel = (ITextChannel)imsg.Channel; - - IEnumerable streams; - using (var uow = DbHandler.UnitOfWork()) - { - streams = uow.GuildConfigs - .For(channel.Guild.Id, - set => set.Include(gc => gc.FollowedStreams)) - .FollowedStreams; - } - - if (!streams.Any()) - { - await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); - return; - } - - var text = string.Join("\n", streams.Select(snc => - { - return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】"; - })); - - await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false); - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task RemoveStream(IUserMessage msg, FollowedStream.FollowedStreamType type, [Remainder] string username) - { - var channel = (ITextChannel)msg.Channel; - - username = username.ToLowerInvariant().Trim(); - - var fs = new FollowedStream() - { - ChannelId = channel.Id, - Username = username, - Type = type - }; - - bool removed; - using (var uow = DbHandler.UnitOfWork()) - { - var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)); - removed = config.FollowedStreams.Remove(fs); - if (removed) - await uow.CompleteAsync().ConfigureAwait(false); - } - if (!removed) - { - await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); - return; - } - await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) - { - var channel = (ITextChannel)imsg.Channel; - - var stream = username?.Trim(); - if (string.IsNullOrWhiteSpace(stream)) - return; - try - { - var streamStatus = (await GetStreamStatus(new FollowedStream - { - Username = stream, - Type = platform, - })); - if (streamStatus.IsLive) - { - await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`"); - } - else - { - await channel.SendMessageAsync($"`Streamer {username} is offline.`"); - } - } - catch - { - await channel.SendMessageAsync("No channel found."); - } - } - - private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) - { - username = username.Trim(); - var fs = new FollowedStream - { - GuildId = channel.Guild.Id, - ChannelId = channel.Id, - Username = username, - Type = type, - }; - - StreamStatus status; - try - { - status = await GetStreamStatus(fs).ConfigureAwait(false); - } - catch - { - await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); - return; - } - - using (var uow = DbHandler.UnitOfWork()) - { - uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) - .FollowedStreams - .Add(fs); - await uow.CompleteAsync().ConfigureAwait(false); - } - - var msg = $":ok: I will notify this channel when status changes."; - await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); - } - } - } - - public static class FollowedStreamExtensions - { - public static EmbedBuilder GetEmbed(this FollowedStream fs, Searches.StreamStatus status) - { - var embed = new EmbedBuilder().WithTitle(fs.Username) - .WithUrl(fs.GetLink()) - .AddField(efb => efb.WithName("Status") - .WithValue(status.IsLive ? "Online" : "Offline") - .WithIsInline(true)) - .AddField(efb => efb.WithName("Viewers") - .WithValue(status.IsLive ? status.Views : "-") - .WithIsInline(true)) - .AddField(efb => efb.WithName("Platform") - .WithValue(fs.Type.ToString()) - .WithIsInline(true)) - .WithColor(status.IsLive ? NadekoBot.OkColor : NadekoBot.ErrorColor); - - return embed; - } - - public static string GetLink(this FollowedStream fs) { - if (fs.Type == FollowedStream.FollowedStreamType.Hitbox) - return $"http://www.hitbox.tv/{fs.Username}/"; - else if (fs.Type == FollowedStream.FollowedStreamType.Twitch) - return $"http://www.twitch.tv/{fs.Username}/"; - else if (fs.Type == FollowedStream.FollowedStreamType.Beam) - return $"https://beam.pro/{fs.Username}/"; - else - return "??"; - } - } -} \ No newline at end of file From 35ca4478da913d86ef855578eb732e2c5af801e5 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:35:37 +0530 Subject: [PATCH 38/43] back up --- .../Commands/StreamNotificationCommands.cs | 410 ++++++++++++++++++ 1 file changed, 410 insertions(+) create mode 100644 src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs new file mode 100644 index 00000000..e038a9d8 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -0,0 +1,410 @@ +ο»Ώusing Discord.Commands; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Concurrent; +using System.Linq; +using System.Threading.Tasks; +using Discord; +using NadekoBot.Services; +using System.Threading; +using System.Collections.Generic; +using NadekoBot.Services.Database.Models; +using System.Net.Http; +using Discord.WebSocket; +using NadekoBot.Attributes; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using NLog; +using NadekoBot.Services.Database; +using NadekoBot.Extensions; + +namespace NadekoBot.Modules.Searches +{ + public partial class Searches + { + public class StreamStatus + { + public bool IsLive { get; set; } + public string ApiLink { get; set; } + public string Views { get; set; } + } + + public class HitboxResponse { + public bool Success { get; set; } = true; + [JsonProperty("media_is_live")] + public string MediaIsLive { get; set; } + public bool IsLive => MediaIsLive == "1"; + [JsonProperty("media_views")] + public string Views { get; set; } + } + + public class TwitchResponse + { + public string Error { get; set; } = null; + public bool IsLive => Stream != null; + public StreamInfo Stream { get; set; } + + public class StreamInfo + { + public int Viewers { get; set; } + } + } + + public class BeamResponse + { + public string Error { get; set; } = null; + + [JsonProperty("online")] + public bool IsLive { get; set; } + public int ViewersCurrent { get; set; } + } + + public class StreamNotFoundException : Exception + { + public StreamNotFoundException(string message) : base("Stream '" + message + "' not found.") + { + } + } + + [Group] + public class StreamNotificationCommands + { + private Timer checkTimer { get; } + private ConcurrentDictionary oldCachedStatuses = new ConcurrentDictionary(); + private ConcurrentDictionary cachedStatuses = new ConcurrentDictionary(); + private Logger _log { get; } + + private bool FirstPass { get; set; } = true; + + public StreamNotificationCommands() + { + + _log = NLog.LogManager.GetCurrentClassLogger(); + checkTimer = new Timer(async (state) => + { + oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); + cachedStatuses.Clear(); + IEnumerable streams; + using (var uow = DbHandler.UnitOfWork()) + { + streams = uow.GuildConfigs.GetAllFollowedStreams(); + } + + await Task.WhenAll(streams.Select(async fs => + { + try + { + var newStatus = await GetStreamStatus(fs).ConfigureAwait(false); + if (FirstPass) + { + return; + } + + StreamStatus oldStatus; + if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) && + oldStatus.IsLive != newStatus.IsLive) + { + var server = NadekoBot.Client.GetGuild(fs.GuildId); + var channel = server?.GetTextChannel(fs.ChannelId); + if (channel == null) + return; + try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { } + } + } + catch (Exception ex) + { + + } + })); + + FirstPass = false; + }, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); + } + + private async Task GetStreamStatus(FollowedStream stream, bool checkCache = true) + { + string response; + StreamStatus result; + switch (stream.Type) + { + case FollowedStream.FollowedStreamType.Hitbox: + var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username.ToLowerInvariant()}"; + if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false); + } + var hbData = JsonConvert.DeserializeObject(response); + if (!hbData.Success) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + result = new StreamStatus() + { + IsLive = hbData.IsLive, + ApiLink = hitboxUrl, + Views = hbData.Views + }; + cachedStatuses.AddOrUpdate(hitboxUrl, result, (key, old) => result); + return result; + case FollowedStream.FollowedStreamType.Twitch: + var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username.ToLowerInvariant())}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6"; + if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false); + } + var twData = JsonConvert.DeserializeObject(response); + if (twData.Error != null) + { + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + } + result = new StreamStatus() + { + IsLive = twData.IsLive, + ApiLink = twitchUrl, + Views = twData.Stream?.Viewers.ToString() ?? "0" + }; + cachedStatuses.AddOrUpdate(twitchUrl, result, (key, old) => result); + return result; + case FollowedStream.FollowedStreamType.Beam: + var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username.ToLowerInvariant()}"; + if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(beamUrl).ConfigureAwait(false); + } + + var bmData = JsonConvert.DeserializeObject(response); + if (bmData.Error != null) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + result = new StreamStatus() + { + IsLive = bmData.IsLive, + ApiLink = beamUrl, + Views = bmData.ViewersCurrent.ToString() + }; + cachedStatuses.AddOrUpdate(beamUrl, result, (key, old) => result); + return result; + default: + break; + } + return null; + } + + //[NadekoCommand, Usage, Description, Aliases] + //[RequireContext(ContextType.Guild)] + //public async Task Test(IUserMessage imsg) + //{ + // var channel = (ITextChannel)imsg.Channel; + + // await channel.EmbedAsync(new Discord.API.Embed() + // { + // Title = "Imqtpie", + // Url = "https://twitch.tv/masterkwoth", + // Fields = new[] { + // new Discord.API.EmbedField() + // { + // Name = "Status", + // Value = "Online", + // Inline = true, + // }, + // new Discord.API.EmbedField() + // { + // Name = "Viewers", + // Value = "123123", + // Inline = true + // }, + // new Discord.API.EmbedField() + // { + // Name = "Platform", + // Value = "Twitch", + // Inline = true + // }, + // }, + // Color = NadekoBot.OkColor + // }); + //} + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Hitbox(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Twitch(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Beam(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task ListStreams(IUserMessage imsg) + { + var channel = (ITextChannel)imsg.Channel; + + IEnumerable streams; + using (var uow = DbHandler.UnitOfWork()) + { + streams = uow.GuildConfigs + .For(channel.Guild.Id, + set => set.Include(gc => gc.FollowedStreams)) + .FollowedStreams; + } + + if (!streams.Any()) + { + await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); + return; + } + + var text = string.Join("\n", streams.Select(snc => + { + return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】"; + })); + + await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task RemoveStream(IUserMessage msg, FollowedStream.FollowedStreamType type, [Remainder] string username) + { + var channel = (ITextChannel)msg.Channel; + + username = username.ToLowerInvariant().Trim(); + + var fs = new FollowedStream() + { + ChannelId = channel.Id, + Username = username, + Type = type + }; + + bool removed; + using (var uow = DbHandler.UnitOfWork()) + { + var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)); + removed = config.FollowedStreams.Remove(fs); + if (removed) + await uow.CompleteAsync().ConfigureAwait(false); + } + if (!removed) + { + await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); + return; + } + await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) + { + var channel = (ITextChannel)imsg.Channel; + + var stream = username?.Trim(); + if (string.IsNullOrWhiteSpace(stream)) + return; + try + { + var streamStatus = (await GetStreamStatus(new FollowedStream + { + Username = stream, + Type = platform, + })); + if (streamStatus.IsLive) + { + await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`"); + } + else + { + await channel.SendMessageAsync($"`Streamer {username} is offline.`"); + } + } + catch + { + await channel.SendMessageAsync("No channel found."); + } + } + + private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) + { + username = username.Trim(); + var fs = new FollowedStream + { + GuildId = channel.Guild.Id, + ChannelId = channel.Id, + Username = username, + Type = type, + }; + + StreamStatus status; + try + { + status = await GetStreamStatus(fs).ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); + return; + } + + using (var uow = DbHandler.UnitOfWork()) + { + uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) + .FollowedStreams + .Add(fs); + await uow.CompleteAsync().ConfigureAwait(false); + } + + var msg = $":ok: I will notify this channel when status changes."; + await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); + } + } + } + + public static class FollowedStreamExtensions + { + public static EmbedBuilder GetEmbed(this FollowedStream fs, Searches.StreamStatus status) + { + var embed = new EmbedBuilder().WithTitle(fs.Username) + .WithUrl(fs.GetLink()) + .AddField(efb => efb.WithName("Status") + .WithValue(status.IsLive ? "Online" : "Offline") + .WithIsInline(true)) + .AddField(efb => efb.WithName("Viewers") + .WithValue(status.IsLive ? status.Views : "-") + .WithIsInline(true)) + .AddField(efb => efb.WithName("Platform") + .WithValue(fs.Type.ToString()) + .WithIsInline(true)) + .WithColor(status.IsLive ? NadekoBot.OkColor : NadekoBot.ErrorColor); + + return embed; + } + + public static string GetLink(this FollowedStream fs) { + if (fs.Type == FollowedStream.FollowedStreamType.Hitbox) + return $"http://www.hitbox.tv/{fs.Username}/"; + else if (fs.Type == FollowedStream.FollowedStreamType.Twitch) + return $"http://www.twitch.tv/{fs.Username}/"; + else if (fs.Type == FollowedStream.FollowedStreamType.Beam) + return $"https://beam.pro/{fs.Username}/"; + else + return "??"; + } + } +} \ No newline at end of file From c17aeaed003c006f623efe83252712018b62d880 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:38:58 +0530 Subject: [PATCH 39/43] Update StreamNotificationCommands.cs --- .../Searches/Commands/StreamNotificationCommands.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index e038a9d8..245081b4 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -303,10 +303,10 @@ namespace NadekoBot.Modules.Searches } if (!removed) { - await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); + await channel.SendMessageAsync("❎ No such stream.").ConfigureAwait(false); return; } - await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); + await channel.SendMessageAsync($"πŸ—‘ Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -358,7 +358,7 @@ namespace NadekoBot.Modules.Searches } catch { - await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); + await channel.SendMessageAsync("πŸ’’ Stream probably doesn't exist.").ConfigureAwait(false); return; } @@ -370,7 +370,7 @@ namespace NadekoBot.Modules.Searches await uow.CompleteAsync().ConfigureAwait(false); } - var msg = $":ok: I will notify this channel when status changes."; + var msg = $"πŸ†— I will notify this channel when status changes."; await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); } } @@ -407,4 +407,4 @@ namespace NadekoBot.Modules.Searches return "??"; } } -} \ No newline at end of file +} From 84c3dff12d8b1d4c09ff1c8ec655412ade96cdec Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:42:18 +0530 Subject: [PATCH 40/43] Delete StreamNotificationCommands.cs --- .../Commands/StreamNotificationCommands.cs | 410 ------------------ 1 file changed, 410 deletions(-) delete mode 100644 src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs deleted file mode 100644 index 245081b4..00000000 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ /dev/null @@ -1,410 +0,0 @@ -ο»Ώusing Discord.Commands; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Threading.Tasks; -using Discord; -using NadekoBot.Services; -using System.Threading; -using System.Collections.Generic; -using NadekoBot.Services.Database.Models; -using System.Net.Http; -using Discord.WebSocket; -using NadekoBot.Attributes; -using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using NLog; -using NadekoBot.Services.Database; -using NadekoBot.Extensions; - -namespace NadekoBot.Modules.Searches -{ - public partial class Searches - { - public class StreamStatus - { - public bool IsLive { get; set; } - public string ApiLink { get; set; } - public string Views { get; set; } - } - - public class HitboxResponse { - public bool Success { get; set; } = true; - [JsonProperty("media_is_live")] - public string MediaIsLive { get; set; } - public bool IsLive => MediaIsLive == "1"; - [JsonProperty("media_views")] - public string Views { get; set; } - } - - public class TwitchResponse - { - public string Error { get; set; } = null; - public bool IsLive => Stream != null; - public StreamInfo Stream { get; set; } - - public class StreamInfo - { - public int Viewers { get; set; } - } - } - - public class BeamResponse - { - public string Error { get; set; } = null; - - [JsonProperty("online")] - public bool IsLive { get; set; } - public int ViewersCurrent { get; set; } - } - - public class StreamNotFoundException : Exception - { - public StreamNotFoundException(string message) : base("Stream '" + message + "' not found.") - { - } - } - - [Group] - public class StreamNotificationCommands - { - private Timer checkTimer { get; } - private ConcurrentDictionary oldCachedStatuses = new ConcurrentDictionary(); - private ConcurrentDictionary cachedStatuses = new ConcurrentDictionary(); - private Logger _log { get; } - - private bool FirstPass { get; set; } = true; - - public StreamNotificationCommands() - { - - _log = NLog.LogManager.GetCurrentClassLogger(); - checkTimer = new Timer(async (state) => - { - oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); - cachedStatuses.Clear(); - IEnumerable streams; - using (var uow = DbHandler.UnitOfWork()) - { - streams = uow.GuildConfigs.GetAllFollowedStreams(); - } - - await Task.WhenAll(streams.Select(async fs => - { - try - { - var newStatus = await GetStreamStatus(fs).ConfigureAwait(false); - if (FirstPass) - { - return; - } - - StreamStatus oldStatus; - if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) && - oldStatus.IsLive != newStatus.IsLive) - { - var server = NadekoBot.Client.GetGuild(fs.GuildId); - var channel = server?.GetTextChannel(fs.ChannelId); - if (channel == null) - return; - try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { } - } - } - catch (Exception ex) - { - - } - })); - - FirstPass = false; - }, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); - } - - private async Task GetStreamStatus(FollowedStream stream, bool checkCache = true) - { - string response; - StreamStatus result; - switch (stream.Type) - { - case FollowedStream.FollowedStreamType.Hitbox: - var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username.ToLowerInvariant()}"; - if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false); - } - var hbData = JsonConvert.DeserializeObject(response); - if (!hbData.Success) - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - result = new StreamStatus() - { - IsLive = hbData.IsLive, - ApiLink = hitboxUrl, - Views = hbData.Views - }; - cachedStatuses.AddOrUpdate(hitboxUrl, result, (key, old) => result); - return result; - case FollowedStream.FollowedStreamType.Twitch: - var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username.ToLowerInvariant())}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6"; - if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false); - } - var twData = JsonConvert.DeserializeObject(response); - if (twData.Error != null) - { - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - } - result = new StreamStatus() - { - IsLive = twData.IsLive, - ApiLink = twitchUrl, - Views = twData.Stream?.Viewers.ToString() ?? "0" - }; - cachedStatuses.AddOrUpdate(twitchUrl, result, (key, old) => result); - return result; - case FollowedStream.FollowedStreamType.Beam: - var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username.ToLowerInvariant()}"; - if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result)) - return result; - using (var http = new HttpClient()) - { - response = await http.GetStringAsync(beamUrl).ConfigureAwait(false); - } - - var bmData = JsonConvert.DeserializeObject(response); - if (bmData.Error != null) - throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); - result = new StreamStatus() - { - IsLive = bmData.IsLive, - ApiLink = beamUrl, - Views = bmData.ViewersCurrent.ToString() - }; - cachedStatuses.AddOrUpdate(beamUrl, result, (key, old) => result); - return result; - default: - break; - } - return null; - } - - //[NadekoCommand, Usage, Description, Aliases] - //[RequireContext(ContextType.Guild)] - //public async Task Test(IUserMessage imsg) - //{ - // var channel = (ITextChannel)imsg.Channel; - - // await channel.EmbedAsync(new Discord.API.Embed() - // { - // Title = "Imqtpie", - // Url = "https://twitch.tv/masterkwoth", - // Fields = new[] { - // new Discord.API.EmbedField() - // { - // Name = "Status", - // Value = "Online", - // Inline = true, - // }, - // new Discord.API.EmbedField() - // { - // Name = "Viewers", - // Value = "123123", - // Inline = true - // }, - // new Discord.API.EmbedField() - // { - // Name = "Platform", - // Value = "Twitch", - // Inline = true - // }, - // }, - // Color = NadekoBot.OkColor - // }); - //} - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Hitbox(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Twitch(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task Beam(IUserMessage msg, [Remainder] string username) => - await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam) - .ConfigureAwait(false); - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task ListStreams(IUserMessage imsg) - { - var channel = (ITextChannel)imsg.Channel; - - IEnumerable streams; - using (var uow = DbHandler.UnitOfWork()) - { - streams = uow.GuildConfigs - .For(channel.Guild.Id, - set => set.Include(gc => gc.FollowedStreams)) - .FollowedStreams; - } - - if (!streams.Any()) - { - await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); - return; - } - - var text = string.Join("\n", streams.Select(snc => - { - return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】"; - })); - - await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false); - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [RequirePermission(GuildPermission.ManageMessages)] - public async Task RemoveStream(IUserMessage msg, FollowedStream.FollowedStreamType type, [Remainder] string username) - { - var channel = (ITextChannel)msg.Channel; - - username = username.ToLowerInvariant().Trim(); - - var fs = new FollowedStream() - { - ChannelId = channel.Id, - Username = username, - Type = type - }; - - bool removed; - using (var uow = DbHandler.UnitOfWork()) - { - var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)); - removed = config.FollowedStreams.Remove(fs); - if (removed) - await uow.CompleteAsync().ConfigureAwait(false); - } - if (!removed) - { - await channel.SendMessageAsync("❎ No such stream.").ConfigureAwait(false); - return; - } - await channel.SendMessageAsync($"πŸ—‘ Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); - } - - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) - { - var channel = (ITextChannel)imsg.Channel; - - var stream = username?.Trim(); - if (string.IsNullOrWhiteSpace(stream)) - return; - try - { - var streamStatus = (await GetStreamStatus(new FollowedStream - { - Username = stream, - Type = platform, - })); - if (streamStatus.IsLive) - { - await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`"); - } - else - { - await channel.SendMessageAsync($"`Streamer {username} is offline.`"); - } - } - catch - { - await channel.SendMessageAsync("No channel found."); - } - } - - private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) - { - username = username.Trim(); - var fs = new FollowedStream - { - GuildId = channel.Guild.Id, - ChannelId = channel.Id, - Username = username, - Type = type, - }; - - StreamStatus status; - try - { - status = await GetStreamStatus(fs).ConfigureAwait(false); - } - catch - { - await channel.SendMessageAsync("πŸ’’ Stream probably doesn't exist.").ConfigureAwait(false); - return; - } - - using (var uow = DbHandler.UnitOfWork()) - { - uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) - .FollowedStreams - .Add(fs); - await uow.CompleteAsync().ConfigureAwait(false); - } - - var msg = $"πŸ†— I will notify this channel when status changes."; - await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); - } - } - } - - public static class FollowedStreamExtensions - { - public static EmbedBuilder GetEmbed(this FollowedStream fs, Searches.StreamStatus status) - { - var embed = new EmbedBuilder().WithTitle(fs.Username) - .WithUrl(fs.GetLink()) - .AddField(efb => efb.WithName("Status") - .WithValue(status.IsLive ? "Online" : "Offline") - .WithIsInline(true)) - .AddField(efb => efb.WithName("Viewers") - .WithValue(status.IsLive ? status.Views : "-") - .WithIsInline(true)) - .AddField(efb => efb.WithName("Platform") - .WithValue(fs.Type.ToString()) - .WithIsInline(true)) - .WithColor(status.IsLive ? NadekoBot.OkColor : NadekoBot.ErrorColor); - - return embed; - } - - public static string GetLink(this FollowedStream fs) { - if (fs.Type == FollowedStream.FollowedStreamType.Hitbox) - return $"http://www.hitbox.tv/{fs.Username}/"; - else if (fs.Type == FollowedStream.FollowedStreamType.Twitch) - return $"http://www.twitch.tv/{fs.Username}/"; - else if (fs.Type == FollowedStream.FollowedStreamType.Beam) - return $"https://beam.pro/{fs.Username}/"; - else - return "??"; - } - } -} From 919ce9a33f50e28f033ab56132c83a0d4d941a84 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:44:44 +0530 Subject: [PATCH 41/43] updated --- .../Commands/StreamNotificationCommands.cs | 410 ++++++++++++++++++ 1 file changed, 410 insertions(+) create mode 100644 src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs new file mode 100644 index 00000000..e038a9d8 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -0,0 +1,410 @@ +ο»Ώusing Discord.Commands; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Concurrent; +using System.Linq; +using System.Threading.Tasks; +using Discord; +using NadekoBot.Services; +using System.Threading; +using System.Collections.Generic; +using NadekoBot.Services.Database.Models; +using System.Net.Http; +using Discord.WebSocket; +using NadekoBot.Attributes; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using NLog; +using NadekoBot.Services.Database; +using NadekoBot.Extensions; + +namespace NadekoBot.Modules.Searches +{ + public partial class Searches + { + public class StreamStatus + { + public bool IsLive { get; set; } + public string ApiLink { get; set; } + public string Views { get; set; } + } + + public class HitboxResponse { + public bool Success { get; set; } = true; + [JsonProperty("media_is_live")] + public string MediaIsLive { get; set; } + public bool IsLive => MediaIsLive == "1"; + [JsonProperty("media_views")] + public string Views { get; set; } + } + + public class TwitchResponse + { + public string Error { get; set; } = null; + public bool IsLive => Stream != null; + public StreamInfo Stream { get; set; } + + public class StreamInfo + { + public int Viewers { get; set; } + } + } + + public class BeamResponse + { + public string Error { get; set; } = null; + + [JsonProperty("online")] + public bool IsLive { get; set; } + public int ViewersCurrent { get; set; } + } + + public class StreamNotFoundException : Exception + { + public StreamNotFoundException(string message) : base("Stream '" + message + "' not found.") + { + } + } + + [Group] + public class StreamNotificationCommands + { + private Timer checkTimer { get; } + private ConcurrentDictionary oldCachedStatuses = new ConcurrentDictionary(); + private ConcurrentDictionary cachedStatuses = new ConcurrentDictionary(); + private Logger _log { get; } + + private bool FirstPass { get; set; } = true; + + public StreamNotificationCommands() + { + + _log = NLog.LogManager.GetCurrentClassLogger(); + checkTimer = new Timer(async (state) => + { + oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); + cachedStatuses.Clear(); + IEnumerable streams; + using (var uow = DbHandler.UnitOfWork()) + { + streams = uow.GuildConfigs.GetAllFollowedStreams(); + } + + await Task.WhenAll(streams.Select(async fs => + { + try + { + var newStatus = await GetStreamStatus(fs).ConfigureAwait(false); + if (FirstPass) + { + return; + } + + StreamStatus oldStatus; + if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) && + oldStatus.IsLive != newStatus.IsLive) + { + var server = NadekoBot.Client.GetGuild(fs.GuildId); + var channel = server?.GetTextChannel(fs.ChannelId); + if (channel == null) + return; + try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { } + } + } + catch (Exception ex) + { + + } + })); + + FirstPass = false; + }, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); + } + + private async Task GetStreamStatus(FollowedStream stream, bool checkCache = true) + { + string response; + StreamStatus result; + switch (stream.Type) + { + case FollowedStream.FollowedStreamType.Hitbox: + var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username.ToLowerInvariant()}"; + if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false); + } + var hbData = JsonConvert.DeserializeObject(response); + if (!hbData.Success) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + result = new StreamStatus() + { + IsLive = hbData.IsLive, + ApiLink = hitboxUrl, + Views = hbData.Views + }; + cachedStatuses.AddOrUpdate(hitboxUrl, result, (key, old) => result); + return result; + case FollowedStream.FollowedStreamType.Twitch: + var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username.ToLowerInvariant())}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6"; + if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false); + } + var twData = JsonConvert.DeserializeObject(response); + if (twData.Error != null) + { + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + } + result = new StreamStatus() + { + IsLive = twData.IsLive, + ApiLink = twitchUrl, + Views = twData.Stream?.Viewers.ToString() ?? "0" + }; + cachedStatuses.AddOrUpdate(twitchUrl, result, (key, old) => result); + return result; + case FollowedStream.FollowedStreamType.Beam: + var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username.ToLowerInvariant()}"; + if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result)) + return result; + using (var http = new HttpClient()) + { + response = await http.GetStringAsync(beamUrl).ConfigureAwait(false); + } + + var bmData = JsonConvert.DeserializeObject(response); + if (bmData.Error != null) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + result = new StreamStatus() + { + IsLive = bmData.IsLive, + ApiLink = beamUrl, + Views = bmData.ViewersCurrent.ToString() + }; + cachedStatuses.AddOrUpdate(beamUrl, result, (key, old) => result); + return result; + default: + break; + } + return null; + } + + //[NadekoCommand, Usage, Description, Aliases] + //[RequireContext(ContextType.Guild)] + //public async Task Test(IUserMessage imsg) + //{ + // var channel = (ITextChannel)imsg.Channel; + + // await channel.EmbedAsync(new Discord.API.Embed() + // { + // Title = "Imqtpie", + // Url = "https://twitch.tv/masterkwoth", + // Fields = new[] { + // new Discord.API.EmbedField() + // { + // Name = "Status", + // Value = "Online", + // Inline = true, + // }, + // new Discord.API.EmbedField() + // { + // Name = "Viewers", + // Value = "123123", + // Inline = true + // }, + // new Discord.API.EmbedField() + // { + // Name = "Platform", + // Value = "Twitch", + // Inline = true + // }, + // }, + // Color = NadekoBot.OkColor + // }); + //} + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Hitbox(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Twitch(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task Beam(IUserMessage msg, [Remainder] string username) => + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam) + .ConfigureAwait(false); + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task ListStreams(IUserMessage imsg) + { + var channel = (ITextChannel)imsg.Channel; + + IEnumerable streams; + using (var uow = DbHandler.UnitOfWork()) + { + streams = uow.GuildConfigs + .For(channel.Guild.Id, + set => set.Include(gc => gc.FollowedStreams)) + .FollowedStreams; + } + + if (!streams.Any()) + { + await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); + return; + } + + var text = string.Join("\n", streams.Select(snc => + { + return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】"; + })); + + await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.ManageMessages)] + public async Task RemoveStream(IUserMessage msg, FollowedStream.FollowedStreamType type, [Remainder] string username) + { + var channel = (ITextChannel)msg.Channel; + + username = username.ToLowerInvariant().Trim(); + + var fs = new FollowedStream() + { + ChannelId = channel.Id, + Username = username, + Type = type + }; + + bool removed; + using (var uow = DbHandler.UnitOfWork()) + { + var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)); + removed = config.FollowedStreams.Remove(fs); + if (removed) + await uow.CompleteAsync().ConfigureAwait(false); + } + if (!removed) + { + await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); + return; + } + await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username) + { + var channel = (ITextChannel)imsg.Channel; + + var stream = username?.Trim(); + if (string.IsNullOrWhiteSpace(stream)) + return; + try + { + var streamStatus = (await GetStreamStatus(new FollowedStream + { + Username = stream, + Type = platform, + })); + if (streamStatus.IsLive) + { + await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`"); + } + else + { + await channel.SendMessageAsync($"`Streamer {username} is offline.`"); + } + } + catch + { + await channel.SendMessageAsync("No channel found."); + } + } + + private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) + { + username = username.Trim(); + var fs = new FollowedStream + { + GuildId = channel.Guild.Id, + ChannelId = channel.Id, + Username = username, + Type = type, + }; + + StreamStatus status; + try + { + status = await GetStreamStatus(fs).ConfigureAwait(false); + } + catch + { + await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); + return; + } + + using (var uow = DbHandler.UnitOfWork()) + { + uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) + .FollowedStreams + .Add(fs); + await uow.CompleteAsync().ConfigureAwait(false); + } + + var msg = $":ok: I will notify this channel when status changes."; + await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); + } + } + } + + public static class FollowedStreamExtensions + { + public static EmbedBuilder GetEmbed(this FollowedStream fs, Searches.StreamStatus status) + { + var embed = new EmbedBuilder().WithTitle(fs.Username) + .WithUrl(fs.GetLink()) + .AddField(efb => efb.WithName("Status") + .WithValue(status.IsLive ? "Online" : "Offline") + .WithIsInline(true)) + .AddField(efb => efb.WithName("Viewers") + .WithValue(status.IsLive ? status.Views : "-") + .WithIsInline(true)) + .AddField(efb => efb.WithName("Platform") + .WithValue(fs.Type.ToString()) + .WithIsInline(true)) + .WithColor(status.IsLive ? NadekoBot.OkColor : NadekoBot.ErrorColor); + + return embed; + } + + public static string GetLink(this FollowedStream fs) { + if (fs.Type == FollowedStream.FollowedStreamType.Hitbox) + return $"http://www.hitbox.tv/{fs.Username}/"; + else if (fs.Type == FollowedStream.FollowedStreamType.Twitch) + return $"http://www.twitch.tv/{fs.Username}/"; + else if (fs.Type == FollowedStream.FollowedStreamType.Beam) + return $"https://beam.pro/{fs.Username}/"; + else + return "??"; + } + } +} \ No newline at end of file From d69d8b4d158aa2960763dda5a7ef61404d1458bb Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:47:37 +0530 Subject: [PATCH 42/43] emojis added --- .../Searches/Commands/StreamNotificationCommands.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index e038a9d8..245081b4 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -303,10 +303,10 @@ namespace NadekoBot.Modules.Searches } if (!removed) { - await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false); + await channel.SendMessageAsync("❎ No such stream.").ConfigureAwait(false); return; } - await channel.SendMessageAsync($":ok: Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); + await channel.SendMessageAsync($"πŸ—‘ Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -358,7 +358,7 @@ namespace NadekoBot.Modules.Searches } catch { - await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false); + await channel.SendMessageAsync("πŸ’’ Stream probably doesn't exist.").ConfigureAwait(false); return; } @@ -370,7 +370,7 @@ namespace NadekoBot.Modules.Searches await uow.CompleteAsync().ConfigureAwait(false); } - var msg = $":ok: I will notify this channel when status changes."; + var msg = $"πŸ†— I will notify this channel when status changes."; await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false); } } @@ -407,4 +407,4 @@ namespace NadekoBot.Modules.Searches return "??"; } } -} \ No newline at end of file +} From c04b6e61e3ac798880183efe7562c5e18c1ffc06 Mon Sep 17 00:00:00 2001 From: samvaio Date: Sun, 4 Dec 2016 01:50:13 +0530 Subject: [PATCH 43/43] Update NadekoBot.cs --- src/NadekoBot/NadekoBot.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index b6342b48..e110a8e2 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -24,8 +24,6 @@ namespace NadekoBot { private Logger _log; - //public static uint OkColor { get; } = 0x00ff00; - //public static uint ErrorColor { get; } = 0xff0000; public static uint OkColor { get; } = 0x71cd40; public static uint ErrorColor { get; } = 0xee281f;