.rotaterolecolor added. closes #936
This commit is contained in:
@ -582,14 +582,10 @@ namespace NadekoBot.Modules.Searches
|
||||
public async Task Color([Remainder] string color = null)
|
||||
{
|
||||
color = color?.Trim().Replace("#", "");
|
||||
if (string.IsNullOrWhiteSpace((string)color))
|
||||
if (string.IsNullOrWhiteSpace(color))
|
||||
return;
|
||||
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));
|
||||
|
||||
await Context.Channel.SendFileAsync(img.ToStream(), $"{color}.png");
|
||||
|
@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
|
@ -10,12 +10,82 @@ using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
using NadekoBot.Services.Impl;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using ImageSharp;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
[NadekoModule("Utility", ".")]
|
||||
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]
|
||||
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>
|
||||
/// Looks up a localized string similar to rps.
|
||||
/// </summary>
|
||||
|
@ -2862,4 +2862,13 @@
|
||||
<data name="setstatus_usage" xml:space="preserve">
|
||||
<value>`{0}setstatus Idle`</value>
|
||||
</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>
|
@ -149,7 +149,7 @@ namespace NadekoBot.Services.Impl
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
//todo AsyncEnumerable
|
||||
public async Task<IReadOnlyDictionary<string,TimeSpan>> GetVideoDurationsAsync(IEnumerable<string> videoIds)
|
||||
{
|
||||
var videoIdsList = videoIds as List<string> ?? videoIds.ToList();
|
||||
|
Reference in New Issue
Block a user