.rotaterolecolor added. closes #936
This commit is contained in:
parent
58ff017bf8
commit
c5037a2c1f
@ -12,8 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NadekoBot", "src\NadekoBot\NadekoBot.xproj", "{45EC1473-C678-4857-A544-07DFE0D0B478}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NadekoBot", "src\NadekoBot\NadekoBot.xproj", "{45EC1473-C678-4857-A544-07DFE0D0B478}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.API", "discord.net\src\Discord.Net.API\Discord.Net.API.xproj", "{834C70DF-1230-4AAA-9C13-48AB232E8D76}"
|
|
||||||
EndProject
|
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "discord.net\src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "discord.net\src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Core", "discord.net\src\Discord.Net.Core\Discord.Net.Core.xproj", "{E5F4786F-58F3-469E-8C87-1908A95436B7}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Core", "discord.net\src\Discord.Net.Core\Discord.Net.Core.xproj", "{E5F4786F-58F3-469E-8C87-1908A95436B7}"
|
||||||
@ -35,12 +33,6 @@ Global
|
|||||||
{45EC1473-C678-4857-A544-07DFE0D0B478}.GlobalNadeko|Any CPU.Build.0 = Release|Any CPU
|
{45EC1473-C678-4857-A544-07DFE0D0B478}.GlobalNadeko|Any CPU.Build.0 = Release|Any CPU
|
||||||
{45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.Build.0 = Release|Any CPU
|
{45EC1473-C678-4857-A544-07DFE0D0B478}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{834C70DF-1230-4AAA-9C13-48AB232E8D76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{834C70DF-1230-4AAA-9C13-48AB232E8D76}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{834C70DF-1230-4AAA-9C13-48AB232E8D76}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{834C70DF-1230-4AAA-9C13-48AB232E8D76}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{834C70DF-1230-4AAA-9C13-48AB232E8D76}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{834C70DF-1230-4AAA-9C13-48AB232E8D76}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
|
{078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
@ -582,14 +582,10 @@ namespace NadekoBot.Modules.Searches
|
|||||||
public async Task Color([Remainder] string color = null)
|
public async Task Color([Remainder] string color = null)
|
||||||
{
|
{
|
||||||
color = color?.Trim().Replace("#", "");
|
color = color?.Trim().Replace("#", "");
|
||||||
if (string.IsNullOrWhiteSpace((string)color))
|
if (string.IsNullOrWhiteSpace(color))
|
||||||
return;
|
return;
|
||||||
var img = new ImageSharp.Image(50, 50);
|
var img = new ImageSharp.Image(50, 50);
|
||||||
|
|
||||||
var red = Convert.ToInt32(color.Substring(0, 2), 16);
|
|
||||||
var green = Convert.ToInt32(color.Substring(2, 2), 16);
|
|
||||||
var blue = Convert.ToInt32(color.Substring(4, 2), 16);
|
|
||||||
|
|
||||||
img.BackgroundColor(new ImageSharp.Color(color));
|
img.BackgroundColor(new ImageSharp.Color(color));
|
||||||
|
|
||||||
await Context.Channel.SendFileAsync(img.ToStream(), $"{color}.png");
|
await Context.Channel.SendFileAsync(img.ToStream(), $"{color}.png");
|
||||||
|
@ -9,6 +9,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Utility
|
namespace NadekoBot.Modules.Utility
|
||||||
|
@ -10,12 +10,82 @@ using System.Text.RegularExpressions;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NadekoBot.Services.Impl;
|
using NadekoBot.Services.Impl;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Threading;
|
||||||
|
using ImageSharp;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Utility
|
namespace NadekoBot.Modules.Utility
|
||||||
{
|
{
|
||||||
[NadekoModule("Utility", ".")]
|
[NadekoModule("Utility", ".")]
|
||||||
public partial class Utility : DiscordModule
|
public partial class Utility : DiscordModule
|
||||||
{
|
{
|
||||||
|
private static ConcurrentDictionary<ulong, Timer> rotatingRoleColors = new ConcurrentDictionary<ulong, Timer>();
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[OwnerOnly]
|
||||||
|
public async Task RotateRoleColor(int timeout, IRole role, params string[] hexes)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)Context.Channel;
|
||||||
|
|
||||||
|
if (timeout < 0 || timeout > 3600)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Timer t;
|
||||||
|
if (timeout == 0 || hexes.Length == 0)
|
||||||
|
{
|
||||||
|
if (rotatingRoleColors.TryRemove(role.Id, out t))
|
||||||
|
{
|
||||||
|
t.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
|
await channel.SendConfirmAsync($"Stopped rotating colors for the **{role.Name}** role").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hexColors = hexes.Select(hex =>
|
||||||
|
{
|
||||||
|
try { return (ImageSharp.Color?)new ImageSharp.Color(hex.Replace("#", "")); } catch { return null; }
|
||||||
|
})
|
||||||
|
.Where(c => c != null)
|
||||||
|
.Select(c => c.Value)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (!hexColors.Any())
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("No colors are in the correct format. Use `#00ff00` for example.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var images = hexColors.Select(color =>
|
||||||
|
{
|
||||||
|
var img = new ImageSharp.Image(50, 50);
|
||||||
|
img.BackgroundColor(color);
|
||||||
|
return img;
|
||||||
|
}).Merge().ToStream();
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
t = new Timer(async (_) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var color = hexColors[i];
|
||||||
|
await role.ModifyAsync(r => r.Color = new Discord.Color(color.R, color.G, color.B)).ConfigureAwait(false);
|
||||||
|
++i;
|
||||||
|
if (i >= hexColors.Length)
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}, null, 0, timeout * 1000);
|
||||||
|
|
||||||
|
rotatingRoleColors.AddOrUpdate(role.Id, t, (key, old) =>
|
||||||
|
{
|
||||||
|
old.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
await channel.SendFileAsync(images, "magicalgirl.jpg", $"Rotating **{role.Name}** role's color.").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
public async Task TogetherTube()
|
public async Task TogetherTube()
|
||||||
{
|
{
|
||||||
|
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -6053,6 +6053,33 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to rotaterolecolor rrc.
|
||||||
|
/// </summary>
|
||||||
|
public static string rotaterolecolor_cmd {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("rotaterolecolor_cmd", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Rotates a roles color on an interval with a list of supplied colors. First argument is interval in seconds. Second argument is a role, followed by a space-separated list of colors in hex. Provide a rolename with a 0 interval to disable..
|
||||||
|
/// </summary>
|
||||||
|
public static string rotaterolecolor_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("rotaterolecolor_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `{0}rrc 1 MyLsdRole #ff0000 #00ff00 #0000ff` or `{0}rrc 0 MyLsdRole`.
|
||||||
|
/// </summary>
|
||||||
|
public static string rotaterolecolor_usage {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("rotaterolecolor_usage", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to rps.
|
/// Looks up a localized string similar to rps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2862,4 +2862,13 @@
|
|||||||
<data name="setstatus_usage" xml:space="preserve">
|
<data name="setstatus_usage" xml:space="preserve">
|
||||||
<value>`{0}setstatus Idle`</value>
|
<value>`{0}setstatus Idle`</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="rotaterolecolor_cmd" xml:space="preserve">
|
||||||
|
<value>rotaterolecolor rrc</value>
|
||||||
|
</data>
|
||||||
|
<data name="rotaterolecolor_desc" xml:space="preserve">
|
||||||
|
<value>Rotates a roles color on an interval with a list of supplied colors. First argument is interval in seconds. Second argument is a role, followed by a space-separated list of colors in hex. Provide a rolename with a 0 interval to disable.</value>
|
||||||
|
</data>
|
||||||
|
<data name="rotaterolecolor_usage" xml:space="preserve">
|
||||||
|
<value>`{0}rrc 1 MyLsdRole #ff0000 #00ff00 #0000ff` or `{0}rrc 0 MyLsdRole`</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -149,7 +149,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
//todo AsyncEnumerable
|
||||||
public async Task<IReadOnlyDictionary<string,TimeSpan>> GetVideoDurationsAsync(IEnumerable<string> videoIds)
|
public async Task<IReadOnlyDictionary<string,TimeSpan>> GetVideoDurationsAsync(IEnumerable<string> videoIds)
|
||||||
{
|
{
|
||||||
var videoIdsList = videoIds as List<string> ?? videoIds.ToList();
|
var videoIdsList = videoIds as List<string> ?? videoIds.ToList();
|
||||||
|
Loading…
Reference in New Issue
Block a user