now >pick has 60 seconds cooldown

This commit is contained in:
Kwoth 2016-12-23 01:11:50 +01:00
parent 9b887b7688
commit 4aaeba34a0
4 changed files with 96 additions and 87 deletions

View File

@ -35,6 +35,8 @@ namespace NadekoBot.Modules.Games
//channelId/last generation
private static ConcurrentDictionary<ulong, DateTime> lastGenerations { get; } = new ConcurrentDictionary<ulong, DateTime>();
private static ConcurrentHashSet<ulong> usersRecentlyPicked { get; } = new ConcurrentHashSet<ulong>();
private static float chance { get; }
private static int cooldown { get; }
private static Logger _log { get; }
@ -101,11 +103,11 @@ namespace NadekoBot.Modules.Games
{
var channel = (ITextChannel)imsg.Channel;
if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
{
await channel.SendErrorAsync("I need manage channel permissions in order to process this command.").ConfigureAwait(false);
if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages || !usersRecentlyPicked.Add(imsg.Author.Id))
return;
}
try
{
List<IUserMessage> msgs;
@ -119,6 +121,12 @@ namespace NadekoBot.Modules.Games
var msg = await channel.SendConfirmAsync($"**{imsg.Author}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
msg.DeleteAfter(10);
}
finally
{
await Task.Delay(60000);
usersRecentlyPicked.TryRemove(imsg.Author.Id);
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]

View File

@ -4767,7 +4767,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to Picks the currency planted in this channel..
/// Looks up a localized string similar to Picks the currency planted in this channel. 60 seconds cooldown..
/// </summary>
public static string pick_desc {
get {

View File

@ -1363,7 +1363,7 @@
<value>pick</value>
</data>
<data name="pick_desc" xml:space="preserve">
<value>Picks the currency planted in this channel.</value>
<value>Picks the currency planted in this channel. 60 seconds cooldown.</value>
</data>
<data name="pick_usage" xml:space="preserve">
<value>`{0}pick`</value>

View File

@ -64,15 +64,22 @@ namespace NadekoBot.Services
_client.MessageReceived += MessageReceivedHandler;
}
private async Task MessageReceivedHandler(IMessage msg)
private Task MessageReceivedHandler(IMessage msg)
{
var usrMsg = msg as IUserMessage;
if (usrMsg == null)
return;
return Task.CompletedTask;
if (usrMsg.Author.IsBot || !NadekoBot.Ready) //no bots
return;
return Task.CompletedTask;
var throwaway = Task.Run(async () =>
{
var sw = new Stopwatch();
sw.Start();
try
{
var guild = (msg.Channel as ITextChannel)?.Guild;
if (guild != null && guild.OwnerId != usrMsg.Author.Id)
@ -139,13 +146,6 @@ namespace NadekoBot.Services
}
catch { }
var throwaway = Task.Run(async () =>
{
var sw = new Stopwatch();
sw.Start();
try
{
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best);
var command = t.Item1;
var permCache = t.Item2;
@ -209,7 +209,8 @@ namespace NadekoBot.Services
_log.Warn(ex.InnerException, "Inner Exception of the error in CommandHandler");
}
});
return;
return Task.CompletedTask;
}
public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {