now >pick has 60 seconds cooldown
This commit is contained in:
		@@ -35,6 +35,8 @@ namespace NadekoBot.Modules.Games
 | 
				
			|||||||
            //channelId/last generation
 | 
					            //channelId/last generation
 | 
				
			||||||
            private static ConcurrentDictionary<ulong, DateTime> lastGenerations { get; } = new ConcurrentDictionary<ulong, DateTime>();
 | 
					            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 float chance { get; }
 | 
				
			||||||
            private static int cooldown { get; }
 | 
					            private static int cooldown { get; }
 | 
				
			||||||
            private static Logger _log { get; }
 | 
					            private static Logger _log { get; }
 | 
				
			||||||
@@ -101,11 +103,11 @@ namespace NadekoBot.Modules.Games
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                var channel = (ITextChannel)imsg.Channel;
 | 
					                var channel = (ITextChannel)imsg.Channel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
 | 
					                if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages || !usersRecentlyPicked.Add(imsg.Author.Id))
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    await channel.SendErrorAsync("I need manage channel permissions in order to process this command.").ConfigureAwait(false);
 | 
					 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					
 | 
				
			||||||
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    List<IUserMessage> msgs;
 | 
					                    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);
 | 
					                    var msg = await channel.SendConfirmAsync($"**{imsg.Author}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
 | 
				
			||||||
                    msg.DeleteAfter(10);
 | 
					                    msg.DeleteAfter(10);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                finally
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    await Task.Delay(60000);
 | 
				
			||||||
 | 
					                    usersRecentlyPicked.TryRemove(imsg.Author.Id);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            [NadekoCommand, Usage, Description, Aliases]
 | 
					            [NadekoCommand, Usage, Description, Aliases]
 | 
				
			||||||
            [RequireContext(ContextType.Guild)]
 | 
					            [RequireContext(ContextType.Guild)]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4767,7 +4767,7 @@ namespace NadekoBot.Resources {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        /// <summary>
 | 
					        /// <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>
 | 
					        /// </summary>
 | 
				
			||||||
        public static string pick_desc {
 | 
					        public static string pick_desc {
 | 
				
			||||||
            get {
 | 
					            get {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1363,7 +1363,7 @@
 | 
				
			|||||||
    <value>pick</value>
 | 
					    <value>pick</value>
 | 
				
			||||||
  </data>
 | 
					  </data>
 | 
				
			||||||
  <data name="pick_desc" xml:space="preserve">
 | 
					  <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>
 | 
				
			||||||
  <data name="pick_usage" xml:space="preserve">
 | 
					  <data name="pick_usage" xml:space="preserve">
 | 
				
			||||||
    <value>`{0}pick`</value>
 | 
					    <value>`{0}pick`</value>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,15 +64,22 @@ namespace NadekoBot.Services
 | 
				
			|||||||
            _client.MessageReceived += MessageReceivedHandler;
 | 
					            _client.MessageReceived += MessageReceivedHandler;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private async Task MessageReceivedHandler(IMessage msg)
 | 
					        private Task MessageReceivedHandler(IMessage msg)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var usrMsg = msg as IUserMessage;
 | 
					            var usrMsg = msg as IUserMessage;
 | 
				
			||||||
            if (usrMsg == null)
 | 
					            if (usrMsg == null)
 | 
				
			||||||
                return;
 | 
					                return Task.CompletedTask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (usrMsg.Author.IsBot || !NadekoBot.Ready) //no bots
 | 
					            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;
 | 
					                    var guild = (msg.Channel as ITextChannel)?.Guild;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (guild != null && guild.OwnerId != usrMsg.Author.Id)
 | 
					                    if (guild != null && guild.OwnerId != usrMsg.Author.Id)
 | 
				
			||||||
@@ -139,13 +146,6 @@ namespace NadekoBot.Services
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    catch { }
 | 
					                    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 t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best);
 | 
				
			||||||
                    var command = t.Item1;
 | 
					                    var command = t.Item1;
 | 
				
			||||||
                    var permCache = t.Item2;
 | 
					                    var permCache = t.Item2;
 | 
				
			||||||
@@ -209,7 +209,8 @@ namespace NadekoBot.Services
 | 
				
			|||||||
                        _log.Warn(ex.InnerException, "Inner Exception of the error in CommandHandler");
 | 
					                        _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) {
 | 
					        public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user