Esempio n. 1
0
        private DateTime setUpPoll()
        {
            DateTime time = DateTime.Now.Add(timeToWait);

            PollController.AddNewPoll(userID, question, time);
            return(time);
        }
Esempio n. 2
0
        public async Task NewPoll(string time, [Remainder] string pollName)
        {
            // Discord user info
            var msg       = Context.Message;
            var discordId = msg.Author.Username;

            //Set all the date time info
            var      currentTime = DateTime.Now;
            var      userTime    = DateTime.Parse(time);
            var      timeToWait  = userTime.Subtract(currentTime);
            TimeSpan timeToGo    = timeToWait;

            PollSchema pollInfo = PollController.AddNewPoll(discordId, pollName, userTime);

            // Handle the timer if its in the past
            if (timeToGo < TimeSpan.Zero)
            {
                await ReplyAsync("Time Passed Fam");
            }

            //EVENT HANDLER FOR THE TIMER REACHING THE TIME
            this.timer = new System.Threading.Timer(x =>
            {
                this.EndPollNote(pollInfo);
            }, null, timeToGo, Timeout.InfiniteTimeSpan);

            //Message to confirm the poll has been set up
            await ReplyAsync($"{discordId} has started a new poll. [id = {pollInfo.Id}] \n {pollName} \n You have until {userTime} to vote! \n Use 'votepoll [id] [yes/no]'");
        }