Ejemplo n.º 1
0
        public async Task Study(CommandContext ctx, [RemainingText] string subject)
        {
            //Get ID and check if exists on the DB
            String UserID = ctx.User.Id.ToString();

            TryAddMember(ctx.Member);

            //Variables
            DateTime StartTime = DateTime.Now;
            InteractivityExtension interactivity     = ctx.Client.GetInteractivity();
            DiscordEmoji           EmojiStopStudying = DiscordEmoji.FromName(ctx.Client, ":octagonal_sign:");
            TimeSpan StudyTime;
            DateTime EndTime;

            //Create and send embed
            DiscordMessage mensaje = await ctx.Member.SendMessageAsync(
                HelperMethods.QuickEmbed($"Studying {subject}", $"Please click on the reaction {EmojiStopStudying} when you stop studying", false
                                         )); //sendembed

            //Create emoji and wait for answer
            await mensaje.CreateReactionAsync(EmojiStopStudying);

            var em = await interactivity.WaitForReactionAsync(xe => xe.Emoji.Equals(EmojiStopStudying), ctx.User, TimeSpan.FromHours(4));

            if (!em.TimedOut)
            {
                //User clicks on the reaction
                EndTime   = DateTime.Now;
                StudyTime = EndTime - StartTime;
                await mensaje.ModifyAsync("",
                                          HelperMethods.QuickEmbed($"Study Ended {subject}", $"You've studied `{subject}` for {StudyTime.Hours}:{StudyTime.Minutes}:{StudyTime.Seconds}", false, DiscordColor.Red.ToString())
                                          );

                DBInterface.Instance.AddTime(UserID, subject, StartTime, EndTime);
            }
            else
            {
                //timeout
                await mensaje.ModifyAsync("",
                                          HelperMethods.QuickEmbed("4 Hours Reached, React to confirm changes", "If not they will be lost.\n*Also this would be a good time to take care for youself and take a break*", false, DiscordColor.Yellow.ToString())
                                          );

                DiscordMessage mencion = await ctx.Member.SendMessageAsync(ctx.Member.Mention);

                //second confirm
                var confirm = await interactivity.WaitForReactionAsync(xe => xe.Emoji.Equals(EmojiStopStudying), ctx.User, TimeSpan.FromMinutes(5));

                if (!confirm.TimedOut)
                {
                    EndTime   = DateTime.Now;
                    StudyTime = EndTime - StartTime;
                    await mensaje.ModifyAsync("",
                                              HelperMethods.QuickEmbed("Finished Studying", $"You've studied `{subject}` for {StudyTime.Hours:00}:{StudyTime.Minutes:00}", false, DiscordColor.Green.ToString())
                                              );

                    DBInterface.Instance.AddTime(UserID, subject, StartTime, EndTime);
                    await mencion.DeleteAsync();
                }
                else
                {
                    //timeout and canel
                    await mensaje.ModifyAsync("",
                                              HelperMethods.QuickEmbed("Exceeded time limit", "No Study time has been added", false, DiscordColor.Red.ToString())
                                              );

                    await mencion.DeleteAsync();
                }
            }
        }