]> jfr.im git - erebus.git/commitdiff
add slowmsgqueue - only sent when no regular messages
authorzonidjan <redacted>
Fri, 16 Sep 2016 04:21:32 +0000 (23:21 -0500)
committerzonidjan <redacted>
Fri, 16 Sep 2016 04:21:32 +0000 (23:21 -0500)
bot.py
erebus.py
modules/trivia.py

diff --git a/bot.py b/bot.py
index c753fe17860649e248d578bcab6f6a6a754aaefa..2c4d82cc4acfb7e3b9f056a653db95148f6b6c5f 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -26,6 +26,7 @@ class Bot(object):
                self.conn = BotConnection(self, bind, server, port)
 
                self.msgqueue = deque()
+               self.slowmsgqueue = deque()
                self.makemsgtimer()
 
 
@@ -164,14 +165,22 @@ class Bot(object):
                                                self.msg(user, "Command not implemented.")
 
        def msg(self, target, msg):
-               if target is None or msg is None: return
+               if target is None or msg is None: return False
 
-               self.msgqueue.append((target,msg))
+               self.msgqueue.append((target, msg))
                if not self.msgtimer.is_alive():
                        self.msgtimer.start()
+               return True
 
-       def fastmsg(self, target, msg):
+       def slowmsg(self, target, msg):
+               if target is None or msg is None: return False
 
+               self.slowmsgqueue.append((target,msg))
+               if not self.msgtimer.is_alive():
+                       self.msgtimer.start()
+               return True
+
+       def fastmsg(self, target, msg):
                if isinstance(target, self.parent.User): target = target.nick
                elif isinstance(target, self.parent.Channel): target = target.name
                elif not isinstance(target, basestring): raise TypeError('Bot.msg() "target" must be Erebus.User, Erebus.Channel, or string')
@@ -187,7 +196,12 @@ class Bot(object):
                try:
                        self.fastmsg(*self.msgqueue.popleft())
                        self.msgtimer.start()
-               except IndexError: pass
+               except IndexError:
+                       try:
+                               self.fastmsg(*self.slowmsgqueue.popleft())
+                               self.msgtimer.start()
+                       except IndexError:
+                               pass
 
        def makemsgtimer(self):
                self.msgtimer = threading.Timer(2, self._popmsg)
index e6c0459af897a6af79ec6cb085a1c01a8ecd22d0..4cd536de93b6a2b0e6b34a4e5fa0ef0492d59d77 100644 (file)
--- a/erebus.py
+++ b/erebus.py
@@ -28,6 +28,8 @@ class Erebus(object):
 
                def msg(self, *args, **kwargs):
                        main.randbot().msg(self, *args, **kwargs)
+               def slowmsg(self, *args, **kwargs):
+                       main.randbot().slowmsg(self, *args, **kwargs)
                def fastmsg(self, *args, **kwargs):
                        main.randbot().fastmsg(self, *args, **kwargs)
 
@@ -87,6 +89,8 @@ class Erebus(object):
 
                def msg(self, *args, **kwargs):
                        self.bot.msg(self, *args, **kwargs)
+               def slowmsg(self, *args, **kwargs):
+                       self.bot.slowmsg(self, *args, **kwargs)
                def fastmsg(self, *args, **kwargs):
                        self.bot.fastmsg(self, *args, **kwargs)
 
index d1455bbe74cef5c94c577a3ddcb941f52337643f..ae9a74ea63ee58759c5569c2fceda585651dfb4b 100644 (file)
@@ -53,8 +53,9 @@ def pts(num):
                return str(state.db['users'][state.db['ranks'][num]]['points'])
        except IndexError:
                return 0
+
 def country(num, default="??"):
-       return lib.mod('userinfo')._get(person(num), 'country', default=default)
+       return lib.mod('userinfo')._get(person(num), 'country', default=default).upper()
 
 class MyTimer(threading._Timer):
        def __init__(self, *args, **kwargs):
@@ -129,9 +130,7 @@ class TriviaState(object):
                        revealloc = findnth(''.join(self.hintstr), '*', revealcount)
                        self.revealpossibilities.remove(revealcount)
                        self.hintstr[revealloc] = answer[revealloc]
-               if oldhintstr != ''.join(self.hintstr): pass
-               else: self.hintstr = self.hintstr.append("!")
-               self.getchan().fastmsg("\00304,01Here's a hint: %s" % (''.join(self.hintstr)))
+               if oldhintstr != ''.join(self.hintstr): self.getchan().fastmsg("\00304,01Here's a hint: %s" % (''.join(self.hintstr)))
 
                self.hintsgiven += 1
 
@@ -530,7 +529,7 @@ def top10(bot, user, chan, realtarget, *args):
        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)])
+       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))
 
 @lib.hook(glevel=lib.ADMIN, needchan=False)
@@ -631,29 +630,29 @@ def addq(bot, user, chan, realtarget, *args):
 
 @lib.hook(needchan=False)
 def triviahelp(bot, user, chan, realtarget, *args):
-       bot.msg(user,             "START")
-       bot.msg(user,             "TOP10")
-       bot.msg(user,             "POINTS        [<user>]")
-       bot.msg(user,             "RANK          [<user>]")
-       bot.msg(user,             "BADQ          <reason> (include info to identify question)")
+       bot.slowmsg(user,             "START")
+       bot.slowmsg(user,             "TOP10")
+       bot.slowmsg(user,             "POINTS        [<user>]")
+       bot.slowmsg(user,             "RANK          [<user>]")
+       bot.slowmsg(user,             "BADQ          <reason> (include info to identify question)")
        if user.glevel >= 1:
-               bot.msg(user,         "SKIP                            (>=KNOWN)")
-               bot.msg(user,         "STOP                            (>=KNOWN)")
-               bot.msg(user,         "FINDQ         <question>        (>=KNOWN)")
+               bot.slowmsg(user,         "SKIP                            (>=KNOWN)")
+               bot.slowmsg(user,         "STOP                            (>=KNOWN)")
+               bot.slowmsg(user,         "FINDQ         <question>        (>=KNOWN)")
                if user.glevel >= lib.STAFF:
-                       bot.msg(user,     "GIVE          <user> [<points>] (>=STAFF)")
-                       bot.msg(user,     "SETNEXT       <q>*<a>           (>=STAFF)")
-                       bot.msg(user,     "ADDQ          <q>*<a>           (>=STAFF)")
-                       bot.msg(user,     "DELETEQ       <q>*<a>           (>=STAFF)  [aka DELQ]")
-                       bot.msg(user,     "BADQS                           (>=STAFF)")
-                       bot.msg(user,     "CLEARBADQS                      (>=STAFF)")
-                       bot.msg(user,     "DELBADQ       <reportid>        (>=STAFF)")
+                       bot.slowmsg(user,     "GIVE          <user> [<points>] (>=STAFF)")
+                       bot.slowmsg(user,     "SETNEXT       <q>*<a>           (>=STAFF)")
+                       bot.slowmsg(user,     "ADDQ          <q>*<a>           (>=STAFF)")
+                       bot.slowmsg(user,     "DELETEQ       <q>*<a>           (>=STAFF)  [aka DELQ]")
+                       bot.slowmsg(user,     "BADQS                           (>=STAFF)")
+                       bot.slowmsg(user,     "CLEARBADQS                      (>=STAFF)")
+                       bot.slowmsg(user,     "DELBADQ       <reportid>        (>=STAFF)")
                        if user.glevel >= lib.ADMIN:
-                               bot.msg(user, "SETTARGET     <points>          (>=ADMIN)")
-                               bot.msg(user, "MAXMISSED     <questions>       (>=ADMIN)")
-                               bot.msg(user, "HINTTIMER     <float seconds>   (>=ADMIN)")
-                               bot.msg(user, "HINTNUM       <hints>           (>=ADMIN)")
-                               bot.msg(user, "QUESTIONPAUSE <float seconds>   (>=ADMIN)")
+                               bot.slowmsg(user, "SETTARGET     <points>          (>=ADMIN)")
+                               bot.slowmsg(user, "MAXMISSED     <questions>       (>=ADMIN)")
+                               bot.slowmsg(user, "HINTTIMER     <float seconds>   (>=ADMIN)")
+                               bot.slowmsg(user, "HINTNUM       <hints>           (>=ADMIN)")
+                               bot.slowmsg(user, "QUESTIONPAUSE <float seconds>   (>=ADMIN)")
 
 @lib.hooknum(417)
 def num_417(bot, textline):