I run an irc bot, written in ruby, running the cinch irc framework. The bot replies with interesting facts and cycles through these facts so you won’t get bored of them. I have set a cool down, so they can’t be shown for 6 hours. Instead of showing the facts it first showed, it now shows randomly selected ones, which could be the ones that have been shown earlier.
line = IO.readlines("facts.txt")
factnumber = rand(line.length)
if fact_not_next_6_hours[factnumber] == true
factnumber = rand(line.length)
m.reply "fact #{factnumber}: #{line[factnumber]}"
fact_not_next_6_hours[factnumber] = true
fact_not_next_6_hours[factnumber] is the variable for the 6 hour cool down; if it’s set to true, cool down is active. I need to do:
factnumber = rand(line.length)
until it gets one that dosen’t have the 6 hour cool down set to true, and then do
m.reply "fact #{factnumber}: #{line[factnumber]}"
fact_not_next_6_hours[factnumber] = true
My first idea was to do multiple ifs, but it didn’t work and I’m sure there is a better way.
You can do:
Or: