Ok, so I'm trying to design a giveaway system for an IRC chatbot. What I want to do is when someone puts in the !giveaway command, it sets isOpen to true for a few minutes (10sec here for testing), so people can do !enter and have their name added to the giveaway list.
My problem is that when I do sleep(), it pauses the code, so it doesn't respond when anyone does !enter until the giveaway is already over.
Are there any alternatives that fit my needs? Or maybe other ways to accomplish this?
Here's my code for the !giveaway and !enter commands.
My problem is that when I do sleep(), it pauses the code, so it doesn't respond when anyone does !enter until the giveaway is already over.
Are there any alternatives that fit my needs? Or maybe other ways to accomplish this?
Here's my code for the !giveaway and !enter commands.
elif "!giveaway" in str(message): def findWinner(): if len(giveaway) == 0: utils.send(s, "The giveaway has ended with no entries.") else: winningNumber = random.randint(0, len(giveaway)) print (giveaway) winningUser = giveaway[winningNumber] print ("Winning Number is "+winningNumber+" and Winning User is "+winningUser) utils.send(s, winningUser+", you've won the giveaway! Look in your PMs for additional info.") utils.send(s, "/w "+winningUser+" This is an automated message. If you just won a sub giveaway, you should recieve your reward shortly. Congratulations again!") def giveawayCom(): giveaway = [] utils.send(s, "A giveaway has just begun! For the next 3 minutes, do !enter to put in your ticket!") isOpen = True sleep(10) isOpen = False utils.send(s, "The giveaway is closed! You may no longer enter.") sleep(1) utils.send(s, "/me is rolling the dice...") findWinner() giveawayCom() elif "!enter" in str(message): if isOpen: if username in giveaway: utils.send(s, username+", you've already entered this giveaway!") else: giveaway.append(username) else: utils.send(s, "There is no giveaway currently happening!")