Skip to content

Commit

Permalink
Add config value supybot.reply.mores.instant.whenPrivate
Browse files Browse the repository at this point in the history
This allows overriding supybot.reply.mores.instant for private messages, where
it is usually more tolerable to send multiple lines.

However, this still defaults to 1, in order to not be abusable by default.
  • Loading branch information
progval committed Aug 24, 2024
1 parent 04e0bd4 commit b075a94
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ def _sendReply(self, s, target, msg, sendImmediately=False,
else:
sendMsg = self.replyIrc.queueMsg

public = bool(self.msg.channel)
private = kwargs.get('private', False) or not public

if isinstance(self.replyIrc, self.__class__):
s = s[:conf.supybot.reply.maximumLength()]
return self.replyIrc.reply(s,
Expand Down Expand Up @@ -813,8 +816,14 @@ def _sendReply(self, s, target, msg, sendImmediately=False,
# (which is used like a stack)
chunks.reverse()

instant = conf.get(conf.supybot.reply.mores.instant,
channel=target, network=self.replyIrc.network)
instant = 0
if private:
# if zero, falls back to supybot.reply.mores.instant
instant = conf.get(conf.supybot.reply.mores.instant.whenPrivate,
network=self.replyIrc.network)
if instant <= 0:
instant = conf.get(conf.supybot.reply.mores.instant,
channel=target, network=self.replyIrc.network)

# Big complex loop ahead, with lots of cases and opportunities for
# off-by-one errors. Here is the meaning of each of the variables
Expand Down Expand Up @@ -912,8 +921,6 @@ def _sendReply(self, s, target, msg, sendImmediately=False,
if '!' in prefix and '@' in prefix:
mask = prefix.split('!', 1)[1]
self._mores[mask] = msgs
public = bool(self.msg.channel)
private = kwargs.get('private', False) or not public
self._mores[msg.nick] = (private, msgs)
return response

Expand Down
7 changes: 7 additions & 0 deletions src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ def commaAndify(seq, *args, **kwargs):
they are formed). Defaults to 1, which means that a more command will be
required for all but the first chunk.""")))

# XXX: User value.
registerNetworkValue(supybot.reply.mores.instant, 'whenPrivate',
registry.NonNegativeInteger(0, _("""Determines how many mores will be sent
instantly (i.e., without the use of the more command, immediately when
they are formed) when sending messages in private. Defaults to 0, which means
that it defaults to the generic supybot.reply.mores.instant value.""")))

registerChannelValue(supybot.reply, 'oneToOne',
registry.Boolean(True, _("""Determines whether the bot will send
multi-message replies in a single message. This defaults to True
Expand Down
56 changes: 56 additions & 0 deletions test/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ def testReplyInstant(self):
"'" + "foo " * 110 + " \x02(2 more messages)\x02")
self.assertNoResponse(" ", timeout=0.1)

# not in private -> no effect
with conf.supybot.reply.mores.instant.inPrivate.context(2):
self.assertResponse(
"eval 'foo '*300",
"'" + "foo " * 110 + " \x02(2 more messages)\x02")
self.assertNoResponse(" ", timeout=0.1)

with conf.supybot.reply.mores.instant.context(2):
self.assertResponse(
"eval 'foo '*300",
Expand All @@ -568,6 +575,55 @@ def testReplyInstant(self):
" " + "foo " * 79 + "'")
self.assertNoResponse(" ", timeout=0.1)

def testReplyInstantInPrivate(self):
self.assertNoResponse(' ')
self.assertResponse(
"eval irc.reply('foo '*300, private=True)",
"foo " * 113 + "\x02(2 more messages)\x02")
self.assertResponse(" ", "None")

with conf.supybot.reply.mores.instant.whenPrivate.context(2):
self.assertResponse(
"eval irc.reply('foo '*300, private=True)",
"foo " * 112 + "foo")
self.assertResponse(
" ",
" foo" * 112 + " \x02(1 more message)\x02")
self.assertResponse(" ", "None")

with conf.supybot.reply.mores.instant.whenPrivate.context(2):
with conf.supybot.reply.mores.instant.context(3): # ignored
self.assertResponse(
"eval irc.reply('foo '*300, private=True)",
"foo " * 112 + "foo")
self.assertResponse(
" ",
" foo" * 112 + " \x02(1 more message)\x02")
self.assertResponse(" ", "None")

# fall back because supybot.reply.mores.instant.inPrivate is 0
with conf.supybot.reply.mores.instant.context(2):
self.assertResponse(
"eval irc.reply('foo '*300, private=True)",
"foo " * 112 + "foo")
self.assertResponse(
" ",
" foo" * 112 + " \x02(1 more message)\x02")
self.assertResponse(" ", "None")

# fall back because supybot.reply.mores.instant.inPrivate is 0
with conf.supybot.reply.mores.instant.context(3):
self.assertResponse(
"eval irc.reply('foo '*300, private=True)",
"foo " * 112 + "foo")
self.assertResponse(
" ",
" foo" * 112 + " ")
self.assertResponse(
" ",
"foo " * 75)
self.assertResponse(" ", "None")

def testReplyPrivate(self):
# Send from a very long nick, which should be taken into account when
# computing the reply overhead.
Expand Down

0 comments on commit b075a94

Please sign in to comment.