This commit is contained in:
Master Kwoth 2017-09-10 03:54:17 +02:00
commit 35176465b1
2 changed files with 3 additions and 69 deletions

View File

@ -49,11 +49,11 @@ To allow users to only see the current song and have a DJ role for queuing follo
* Disables music commands for everybody
2. `.sc !!nowplaying enable`
2. `.sc .nowplaying enable`
* Enables the "nowplaying" command for everyone
3. `.sc !!listqueue enable`
3. `.sc .listqueue enable`
* Enables the "listqueue" command for everyone

View File

@ -24,7 +24,6 @@ namespace NadekoBot.Modules.Utility
{
public partial class Utility : NadekoTopLevelModule
{
private static ConcurrentDictionary<ulong, Timer> _rotatingRoleColors = new ConcurrentDictionary<ulong, Timer>();
private readonly DiscordSocketClient _client;
private readonly IStatsService _stats;
private readonly IBotCredentials _creds;
@ -36,71 +35,6 @@ namespace NadekoBot.Modules.Utility
_stats = stats;
_creds = creds;
_shardCoord = nadeko.ShardCoord;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageRoles)]
[OwnerOnly]
public async Task RotateRoleColor(int timeout, IRole role, params string[] hexes)
{
var channel = (ITextChannel)Context.Channel;
if ((timeout < 60 && 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 ReplyConfirmLocalized("rrc_stop", Format.Bold(role.Name)).ConfigureAwait(false);
}
return;
}
var hexColors = hexes.Select(hex =>
{
try { return (Rgba32?)Rgba32.FromHex(hex.Replace("#", "")); } catch { return null; }
})
.Where(c => c != null)
.Select(c => c.Value)
.ToArray();
if (!hexColors.Any())
{
await ReplyErrorLocalized("rrc_no_colors").ConfigureAwait(false);
return;
}
var images = hexColors.Select(color =>
{
var img = new ImageSharp.Image<Rgba32>(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 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", GetText("rrc_start", Format.Bold(role.Name))).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@ -430,4 +364,4 @@ namespace NadekoBot.Modules.Utility
await Context.Channel.SendConfirmAsync($"{Format.Bold(Context.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms").ConfigureAwait(false);
}
}
}
}