Exemple #1
0
        private async Task <bool> ValidateLastRunTime(CommandMessage message, CurrencyGame gameType)
        {
            // Guild id
            ulong guildId = message.Guild.Id;

            // Set variables
            DateTime?guildLastRunTime     = null;
            bool     runTimeContainsGuild = this.LastRunTimeForType(gameType).ContainsKey(guildId);

            if (runTimeContainsGuild)
            {
                guildLastRunTime = this.LastRunTimeForType(gameType)[guildId];
            }

            if (runTimeContainsGuild &&
                guildLastRunTime.HasValue &&
                (DateTime.Now - guildLastRunTime.Value).TotalSeconds < 30)
            {
                double timeToWait = 30 - (DateTime.Now - guildLastRunTime.Value).TotalSeconds;

                IUserMessage response = await message.Channel.SendMessageAsync("Sorry, you need to wait another " + Math.Floor(timeToWait) + " seconds, _kupo!_");

                await Task.Delay(2000);

                await message.Channel.DeleteMessageAsync(message.Id);

                await response.DeleteAsync();

                return(false);
            }

            return(true);
        }
Exemple #2
0
 private Dictionary <ulong, DateTime?> LastRunTimeForType(CurrencyGame gameType)
 {
     return(gameType switch
     {
         CurrencyGame.Slots => this.slotsLastRunTime,
         CurrencyGame.Blackjack => this.blackjackLastRunTime,
         _ => new Dictionary <ulong, DateTime?>(),
     });
Exemple #3
0
        private async void UpdateLastRunTime(CurrencyGame gameType, ulong userId, ulong guildId)
        {
            this.LastRunTimeForType(gameType).UpdateOrAdd(guildId, DateTime.Now);

            // Update game count if restricted
            LeaderboardSettings settings = await LeaderboardSettingsService.GetSettings <LeaderboardSettings>(guildId);

            if (settings.CurrencyGamesAllowedPerDay > 0 && settings.CurrencyGamesAllowedPerDay < 2880)
            {
                if (!this.userDailyGameCount.TryGetValue(userId, out uint gameCount))
                {
                    gameCount = 0;
                }

                this.userDailyGameCount.UpdateOrAdd(userId, ++gameCount);
            }
        }