return lib.modstart(parent, *args, **kwargs)
def modstop(*args, **kwargs):
global state
- stop()
- state.closeshop()
- del state
+ try:
+ stop()
+ state.closeshop()
+ del state
+ except Exception: pass
return lib.modstop(*args, **kwargs)
# module code
return -1
return len(haystack)-len(parts[-1])-len(needle)
+def person(num): return state.db['users'][state.db['ranks'][num]]['realnick']
+def pts(num): return str(state.db['users'][state.db['ranks'][num]]['points'])
+def country(num, default="??"): return lib.mod('userinfo').get(person(num), 'country', default=default)
+
class TriviaState(object):
def __init__(self, parent=None, pointvote=False):
if parent is not None:
def gotParent(self, parent, pointvote=False):
self.parent = parent
- self.questionfile = self.parent.cfg.get('trivia', 'jsonpath')
+ self.questionfile = self.parent.cfg.get('trivia', 'jsonpath', default="./modules/trivia.json")
self.db = json.load(open(self.questionfile, "r"))
self.chan = self.db['chan']
self.curq = None
def doGameOver(self):
msg = self.getchan().msg
- def person(num): return self.db['users'][self.db['ranks'][num]]['realnick']
- def pts(num): return str(self.db['users'][self.db['ranks'][num]]['points'])
winner = person(0)
try:
msg("\00312THE GAME IS OVER!!!")
if skipwait:
self._nextquestion(qskipped, iteration)
else:
- print "making timer"
self.nextquestiontimer = threading.Timer(self.db['questionpause'], self._nextquestion, args=[qskipped, iteration])
self.nextquestiontimer.start()
def _nextquestion(self, qskipped, iteration):
- print "_"
if self.nextq is not None:
nextq = self.nextq
self.nextq = None
@lib.hook('points', needchan=False)
def cmd_points(bot, user, chan, realtarget, *args):
- if chan == realtarget: replyto = chan
+ if realtarget == chan.name: replyto = chan
else: replyto = user
if len(args) != 0: who = args[0]
@lib.hook('start', needchan=False)
def cmd_start(bot, user, chan, realtarget, *args):
- if chan == realtarget: replyto = chan
+ if realtarget == chan.name: replyto = chan
else: replyto = user
if state.curq is None and state.pointvote is None and state.nextquestiontimer is None:
@lib.hook('rank', needchan=False)
def cmd_rank(bot, user, chan, realtarget, *args):
- if chan == realtarget: replyto = chan
+ if realtarget == chan.name: replyto = chan
else: replyto = user
if len(args) != 0: who = args[0]
if len(state.db['ranks']) == 0:
return bot.msg(state.db['chan'], "No one is ranked!")
- replylist = []
- for nick in state.db['ranks'][0:10]:
- user = state.db['users'][nick]
- replylist.append("%s (%s)" % (user['realnick'], user['points']))
- bot.msg(state.db['chan'], ', '.join(replylist))
+ max = len(state.db['ranks'])
+ if max > 10:
+ max = 10
+ replylist = ', '.join(["%s (%s) %s" % (person(x), country(x, "unknown"), pts(x)) for x in range(max)])
+ bot.msg(state.db['chan'], "Top %d: %s" % (max, replylist))
@lib.hook('settarget', glevel=lib.ADMIN, needchan=False)
def cmd_settarget(bot, user, chan, realtarget, *args):
@lib.hook('triviahelp', needchan=False)
def cmd_triviahelp(bot, user, chan, realtarget, *args):
- if user.glevel == 0:
+ if user.glevel <= 0:
bot.msg(user, "START")
bot.msg(user, "TOP10")
bot.msg(user, "POINTS [<user>]")
formatted = state.db['topicformat'] % {
'chan': state.db['chan'],
- 'top': state.db['users'][state.db['ranks'][0]]['realnick'],
- 'top3': '/'.join([state.db['users'][state.db['ranks'][x]]['realnick'] for x in range(3) if x < len(state.db['ranks'])]),
- 'topscore': state.db['users'][state.db['ranks'][0]]['points'],
+ 'top1': "%s (%s)" % (person(0), pts(0)),
+ 'top3': '/'.join([
+ "%s (%s)" % (person(x), pts(x))
+ for x in range(3) if x < len(state.db['ranks'])
+ ]),
+ 'top3c': ' '.join([
+ "%s (%s, %s)" % (person(x), pts(x), country(x))
+ for x in range(3) if x < len(state.db['ranks'])
+ ]),
+ 'top10': ' '.join([
+ "%s (%s)" % (person(x), pts(x))
+ for x in range(10) if x < len(state.db['ranks'])
+ ]),
+ 'top10c': ' '.join([
+ "%s (%s, %s)" % (person(x), pts(x), country(x))
+ for x in range(10) if x < len(state.db['ranks'])
+ ]),
'target': state.db['target'],
}
if gottopic != formatted: