]> jfr.im git - erebus.git/commitdiff
allow modules to specify that a message should be sent as NOTICE vs PRIVMSG
authorJohn Runyon <redacted>
Thu, 15 Jun 2023 02:57:52 +0000 (20:57 -0600)
committerJohn Runyon <redacted>
Thu, 15 Jun 2023 02:57:52 +0000 (20:57 -0600)
bot.py
modules/reddark.py

diff --git a/bot.py b/bot.py
index 4b0ecc04b277fdea46dbc9e38d01271ff84e4f43..366eda2db45efc2f789dcc419f6f2f65885f6a79 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -395,10 +395,10 @@ class Bot(object):
 
                In the case of fastmsg, self.conn.exceeded may be True, however, in this case append_callback=self.conn.send, so it will still be sent immediately.
        """
-       def _msg(self, target, msg, truncate, append_callback):
+       def _msg(self, target, msg, truncate, append_callback, msgtype):
                if self.parent.cfg.getboolean('erebus', 'nofakelag'): return self.fastmsg(target, msg)
 
-               cmd = self._formatmsg(target, msg)
+               cmd = self._formatmsg(target, msg, msgtype)
                # The max length is much shorter than recvq (510) because of the length the server adds on about the source (us).
                # If you know your hostmask, you can of course figure the exact length, but it's very difficult to reliably know your hostmask.
                maxlen = (
@@ -422,22 +422,24 @@ class Bot(object):
                self.conn.exceeded = True
                return True
 
-       def msg(self, target, msg, truncate=False):
-               return self._msg(target, msg, truncate, self.msgqueue.append)
+       def msg(self, target, msg, truncate=False, *, msgtype=None):
+               """msgtype must be a valid IRC command, i.e. NOTICE or PRIVMSG; or leave as None to use default"""
+               return self._msg(target, msg, truncate, self.msgqueue.append, msgtype)
 
-       def slowmsg(self, target, msg, truncate=False):
-               return self._msg(target, msg, truncate, self.slowmsgqueue.append)
+       def slowmsg(self, target, msg, truncate=False, *, msgtype=None):
+               return self._msg(target, msg, truncate, self.slowmsgqueue.append, msgtype)
 
-       def fastmsg(self, target, msg, truncate=False):
-               return self._msg(target, msg, truncate, self.conn.send)
+       def fastmsg(self, target, msg, truncate=False, *, msgtype=None):
+               return self._msg(target, msg, truncate, self.conn.send, msgtype)
 
-       def _formatmsg(self, target, msg):
+       def _formatmsg(self, target, msg, msgtype):
                if target is None or msg is None:
                        return self.__debug_nomsg(target, msg)
 
                target = str(target)
 
-               if target.startswith('#'): command = "PRIVMSG %s :%s" % (target, msg)
+               if msgtype is not None: command = "%s %s :%s" % (msgtype, target, msg)
+               elif target.startswith('#'): command = "PRIVMSG %s :%s" % (target, msg)
                else: command = "NOTICE %s :%s" % (target, msg)
 
                return command
index 0ade6d3824bb3d28e79863f39e9e42ebe21789d7..22383e746b75ce4e0d8dfb60b00f33eab988bdc4 100644 (file)
@@ -50,6 +50,9 @@ def chan():
 def bot():
        return chan().bot
 
+def chanmsg(message):
+       return chan().msg(message, truncate=True, msgtype="NOTICE")
+
 def debug(message, send_to_owner=True):
        if lib.parent is None:
                print(message)
@@ -86,11 +89,11 @@ def handleDelta(message):
        if message['state'] == 'private':
                message['text'] = getText(message['name'])
                print(repr(message))
-               chan().msg('[%(section)s] %(name)s went %(state)s (was: %(previous_state)s) (https://old.reddit.com/%(name)s)%(text)s' % message, truncate=True)
+               chanmsg('[%(section)s] %(name)s went %(state)s (was: %(previous_state)s) (https://old.reddit.com/%(name)s)%(text)s' % message)
        elif message['state'] == 'restricted':
-               chan().msg('[%(section)s] %(name)s went %(state)s (was: %(previous_state)s) (https://old.reddit.com/%(name)s)' % message, truncate=True)
+               chanmsg('[%(section)s] %(name)s went %(state)s (was: %(previous_state)s) (https://old.reddit.com/%(name)s)' % message)
        else:
-               chan().msg('[%(section)s] %(name)s went \x02%(state)s\x02 (was: %(previous_state)s) (https://old.reddit.com/%(name)s)' % message, truncate=True)
+               chanmsg('[%(section)s] %(name)s went \x02%(state)s\x02 (was: %(previous_state)s) (https://old.reddit.com/%(name)s)' % message)
 
 def handleState(message):
        global last_update, last_topic