public async Task RegisterJob(DiggingJob job)
        {
            // Do not continue if consent was lost.
            if (!_gudp.GlobalDataExists(job.UserId))
            {
                return;
            }

#if DEBUG
            // In DEBUG, we need to wait for SECONDS instead of HOURS
            // to be able to test the feature without actually waiting.
            var finishDateTime = job.StartDateTime.AddSeconds(job.DiggingLengthInHours);
            //var finishDateTime = job.StartDateTime.AddSeconds(20);
#else
            var finishDateTime = job.StartDateTime.AddHours(job.DiggingLengthInHours);
#endif

            // Finish if past due-date.
            if (finishDateTime < DateTime.Now)
            {
                await FinishDigging(job);

                return;
            }

            var user = _gudp.GetGlobalUserData(job.UserId);

            JustineCore.SchedulerUtilities.ExecuteAt(async() => {
                await FinishDigging(job);
            }, finishDateTime);

            Logger.Log($"[RegisterAllDiggingJobs] Scheduled a stored job.");
        }
        public async Task FinishDigging(DiggingJob job)
        {
            if (job is null)
            {
                return;
            }
            if (!_gudp.GlobalDataExists(job.UserId))
            {
                return;
            }

            try
            {
                var discordUser = _client.GetUser(job.UserId);

                var g  = _client.GetGuild(job.GuildId);
                var ch = g.GetTextChannel(job.TextChannelId);

                await ch.SendMessageAsync($"{discordUser.Mention}, you finished your digging! Use `gold dig reward` to collect your reward.");
            }
            catch
            {
                Logger.Log("[DiggingJobProvider] Couldn't send a completion message.", ConsoleColor.Red);
            }
        }
Example #3
0
        public static int GetReward(this DiggingJob job)
        {
            var reward = job.DiggingLengthInHours * Constants.DiggingGoldPerHour;

            if (job.DiggingLengthInHours > 1)
            {
                reward += job.DiggingLengthInHours * Constants.StreakBonusPerHour;
            }

            return(reward);
        }
        public async void AddJob(DiggingJob job)
        {
            if (_activeJobs.Any(j => j.UserId == job.UserId))
            {
                return;
            }

            _activeJobs.Add(job);
            SaveJobs();

            await RegisterJob(job);
        }
Example #5
0
        public static bool IsComplete(this DiggingJob job)
        {
#if DEBUG
            // In DEBUG, we need to wait for SECONDS instead of HOURS
            // to be able to test the feature without actually waiting.
            var finishDateTime = job.StartDateTime.AddSeconds(job.DiggingLengthInHours);
            //var finishDateTime = job.StartDateTime.AddSeconds(20);
#else
            var finishDateTime = job.StartDateTime.AddHours(job.DiggingLengthInHours);
#endif
            return(finishDateTime < DateTime.Now);
        }