]> jfr.im git - erebus.git/commitdiff
reddark - add topic suffix and move updateinterval to config
authorJohn Runyon <redacted>
Wed, 14 Jun 2023 12:16:39 +0000 (06:16 -0600)
committerJohn Runyon <redacted>
Wed, 14 Jun 2023 12:16:39 +0000 (06:16 -0600)
modules/reddark.py

index 2a4ce8b9f4e5dd2ecc69b8079681799857608f90..ad0a30fcba0836ba85dcc8967ac9f8bfa6f42767 100644 (file)
@@ -20,7 +20,6 @@ modinfo = {
 wants_to_stop = False
 runner = None
 last_update = 0
-update_interval = 600
 last_topic = ""
 
 # preamble
@@ -33,8 +32,8 @@ def modstop(*args, **kwargs):
        global wants_to_stop, runner
        if runner:
                debug("Stopping runner")
-               wants_to_stop = True
-               runner.join()
+               wants_to_stop = True # tell the SSE thread to stop the next time it wakes up
+               runner.join() # blocks the main thread til the next chunk received (or timeout)! oh well.
                debug("runner stopped")
                wants_to_stop = False
        return lib.modstop(*args, **kwargs)
@@ -93,8 +92,8 @@ def handleDelta(message):
                chan().msg('[%(section)s] %(name)s went \x02%(state)s\x02 (was: %(previous_state)s) (https://old.reddit.com/%(name)s)' % message, truncate=True)
 
 def handleState(message):
-       global last_update, update_interval, last_topic
-       if time.time() < last_update+update_interval:
+       global last_update, last_topic
+       if time.time() < last_update + lib.parent.cfg.getint('reddark', 'update_interval', 600):
                return
        output = collections.defaultdict(int)
        output['totalSubs'] = len(message['subreddits'])
@@ -116,7 +115,7 @@ def handleState(message):
        if last_topic != newTopic:
                last_topic = newTopic
                last_update = time.time()
-               bot().conn.send("TOPIC %(chan)s :%(topic)s" % {'chan': chan(), 'topic': newTopic})
+               bot().conn.send("TOPIC %(chan)s :%(topic)s %(suffix)s" % {'chan': chan(), 'topic': newTopic, 'suffix': lib.parent.cfg.get('reddark', 'topicsuffix', '| Reddark That Works™ https://reddark.rewby.archivete.am/ (https://github.com/reddark-remix/reddark-remix) | https://www.youtube.com/watch?v=xMaE6toi4mk')})
 
 def gotParent(parent):
        global runner
@@ -146,7 +145,7 @@ def gotParent(parent):
        runner.start()
 
 @lib.hook(needchan=False, glevel=50)
-@lib.help(None, 'sets reddark topic suffix')
+@lib.help('[<suffix>]', 'sets reddark topic suffix')
 def topicsuffix(bot, user, chan, realtarget, *args):
        if chan is not None: replyto = chan
        else: replyto = user
@@ -154,3 +153,14 @@ def topicsuffix(bot, user, chan, realtarget, *args):
        lib.parent.cfg.set('reddark', 'topicsuffix', ' '.join(args))
 
        bot.msg(replyto, "Updated topic suffix")
+
+@lib.hook(needchan=False, glevel=50)
+@lib.help('<seconds>', 'sets reddark topic max update interval')
+@lib.argsEQ(1)
+def updateinterval(bot, user, chan, realtarget, *args):
+       if chan is not None: replyto = chan
+       else: replyto = user
+
+       lib.parent.cfg.set('reddark', 'update_interval', int(' '.join(args)))
+
+       bot.msg(replyto, "Updated topic interval")