wants_to_stop = False
runner = None
last_update = 0
-update_interval = 600
last_topic = ""
# preamble
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)
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'])
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
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
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")