Merge pull request #132 from deathbybandaid/development

Development
This commit is contained in:
Deathbybandaid 2019-10-01 16:00:34 -04:00 committed by GitHub
commit 845d12d3f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View File

@ -77,7 +77,7 @@ class ToolsOSD:
return recipientgroups return recipientgroups
def get_available_message_bytes(bot, recipientgroups): def get_available_message_bytes(bot, recipientgroups, text_method):
""" """
Get total available bytes for sending a message line Get total available bytes for sending a message line
@ -89,23 +89,42 @@ class ToolsOSD:
sendable message length sendable message length
""" """
available_bytes = 512 if text_method == 'ACTION':
reserved_irc_bytes = 15 text_method = "\x01ACTION \x01"
available_bytes -= reserved_irc_bytes
# available_bytes = 512
# reserved_irc_bytes = 15
# available_bytes -= reserved_irc_bytes
try: try:
hostmaskbytes = len((bot.users.get(bot.nick).hostmask).encode('utf-8')) hostmaskbytes = len((bot.users.get(bot.nick).hostmask).encode('utf-8'))
except AttributeError: except AttributeError:
hostmaskbytes = len((bot.nick).encode('utf-8')) + 12 + 63 # hostmaskbytes = len((bot.nick).encode('utf-8')) + 12 + 63
available_bytes -= hostmaskbytes hostmaskbytes = (len((bot.nick).encode('utf-8')) # Bot's NICKLEN
+ 1 # (! separator)
+ len('~') # (for the optional ~ in user)
+ 9 # max username length
+ 1 # (@ separator)
+ 63 # <hostname> has a maximum length of 63 characters.
)
# available_bytes -= hostmaskbytes
# find the maximum target group length, and use the max
groupbytes = [] groupbytes = []
for recipients_part in recipientgroups: for recipients_part in recipientgroups:
groupbytes.append(len((recipients_part).encode('utf-8'))) groupbytes.append(len((recipients_part).encode('utf-8')))
max_recipients_bytes = max(groupbytes) max_recipients_bytes = max(groupbytes)
available_bytes -= max_recipients_bytes # available_bytes -= max_recipients_bytes
return available_bytes allowedLength = (512
- len(':') - hostmaskbytes
- len(' ' + text_method + ' ')
- max_recipients_bytes
- len(' :')
- len('\r\n')
)
return allowedLength
def get_sendable_message_list(messages, max_length=400): def get_sendable_message_list(messages, max_length=400):
"""Get a sendable ``text`` message list. """Get a sendable ``text`` message list.
@ -198,7 +217,7 @@ class SopelOSD:
text_method = 'PRIVMSG' text_method = 'PRIVMSG'
recipientgroups = tools.get_message_recipientgroups(self, recipients, text_method) recipientgroups = tools.get_message_recipientgroups(self, recipients, text_method)
available_bytes = tools.get_available_message_bytes(self, recipientgroups) available_bytes = tools.get_available_message_bytes(self, recipientgroups, text_method)
messages_list = tools.get_sendable_message_list(messages, available_bytes) messages_list = tools.get_sendable_message_list(messages, available_bytes)
if max_messages >= 1: if max_messages >= 1:

View File

@ -10,7 +10,7 @@ import sopel_modules.SpiceBot as SpiceBot
import time import time
@sopel.module.event(SpiceBot.events.BOT_CONNECTED) @sopel.module.event(SpiceBot.events.BOT_CHANNELS)
@sopel.module.rule('.*') @sopel.module.rule('.*')
def bot_startup_monologue_start(bot, trigger): def bot_startup_monologue_start(bot, trigger):
# Startup # Startup