# Erebus IRC bot - Author: Erebus Team
+# vim: fileencoding=utf-8
# trivia module
# This file is released into the public domain; see http://unlicense.org/
return 0
def country(num, default="??"):
- return lib.mod('userinfo')._get(person(num), 'country', default=default).upper()
+ return lib.mod('userinfo').get(person(num), 'country', default=default).upper()
class MyTimer(timerbase):
def __init__(self, *args, **kwargs):
self.db['lastwon'] = time.time()
if pointvote:
- self.getchan().msg("Vote for the next round target points! Options: %s. Vote using !vote <choice>" % (', '.join([str(x) for x in self.db['targetoptions']])))
- self.getchan().msg("You have %s seconds." % (self.db['votetimer']))
+ self.getchan().fastmsg("Vote for the next round target points! Options: %s. Vote using !vote <choice>" % (', '.join([str(x) for x in self.db['targetoptions']])))
+ self.getchan().fastmsg("You have %s seconds." % (self.db['votetimer']))
self.voteamounts = dict([(x, 0) for x in self.db['targetoptions']]) # make a dict {pointsoptionA: 0, pointsoptionB: 0, ...}
self.pointvote = MyTimer(self.db['votetimer'], self.endPointVote)
self.pointvote.start()
else:
oldhintstr = ''.join(self.hintstr)
- for i in range(self.reveal):
- revealcount = random.choice(self.revealpossibilities)
- revealloc = findnth(''.join(self.hintstr), '*', revealcount)
- self.revealpossibilities.remove(revealcount)
- self.hintstr[revealloc] = answer[revealloc]
+ try:
+ for i in range(self.reveal):
+ revealcount = random.choice(self.revealpossibilities)
+ revealloc = findnth(''.join(self.hintstr), '*', revealcount)
+ self.revealpossibilities.remove(revealcount)
+ self.hintstr[revealloc] = answer[revealloc]
+ except IndexError: pass # if everything is revealed, random.choice will IndexError
if oldhintstr != ''.join(self.hintstr): self.getchan().fastmsg("\00304,01Here's a hint: %s" % (''.join(self.hintstr)))
self.hintsgiven += 1
self.db['users'] = {}
self.db['ranks'] = []
+ self.savedb()
stop()
self.closeshop()
except: return 0
status = False
+ f = None
try:
f = open(self.db['hofpath'], 'rb+')
for i in range(self.db['hoflines']): #skip this many lines
except Exception as e:
status = False
finally:
- f.close()
+ if f is not None:
+ f.close()
return status
def endPointVote(self):
)
qtext += "\00304,01"+qword+"\00301,01"+chr(spacer) #a-z
if not self.getbot().fastmsg(self.chan, qtext): #if message is too long:
- if nextqid is None: nextqid = "manual"
- self.getbot().slowmsg(self.chan, "(Unable to ask question #%s: line too long)" % (nextqid))
- return self._nextquestion(iteration) #retry; don't increment the iteration
+ if not self.getbot().fastmsg(self.chan, "\00312,01Next up: " + ("(%5d)" % (random.randint(0,99999))) + "\00304,01" + nextq[0]):
+ if nextqid is None: nextqid = "manual"
+ self.getbot().slowmsg(self.chan, "(Unable to ask question #%s: line too long)" % (nextqid))
+ return self._nextquestion(iteration) #retry; don't increment the iteration
self.curq = nextq
self.curqid = nextqid
if max > 10:
max = 10
replylist = ', '.join(["%s (%s) %s" % (person(x), country(x), pts(x)) for x in range(max)])
- bot.msg(state.db['chan'], "Top 10: %s" % (replylist))
+ bot.msg(state.db['chan'], "Game is to %s! Top 10: %s" % (state.db['target'], replylist))
@lib.hook(glevel=lib.ADMIN, needchan=False)
@lib.help("<target score>", "changes the target score for this round")
bot.slowmsg(user, "HINTNUM <hints> (ADMIN)")
bot.slowmsg(user, "QUESTIONPAUSE <float seconds> (ADMIN)")
-@lib.hooknum(332)
+@lib.hooknum(332) # topic is...
+@lib.hooknum(331) # no topic set
def num_TOPIC(bot, textline):
pieces = textline.split(None, 4)
chan = pieces[3]
'category': state.db['category'],
}
if gottopic != formatted:
- state.getbot().conn.send("TOPIC %s :%s" % (state.db['chan'], formatted))
+ state.getbot().conn.send(bot.parent.cfg.get('trivia', 'topiccommand', default="TOPIC %(chan)s :%(topic)s") % {'chan': state.db['chan'], 'topic': formatted})
def specialQuestion(oldq):