Skip to content

Commit

Permalink
Merge pull request #1956 from sopel-irc/adminchannel-use-topiclen
Browse files Browse the repository at this point in the history
adminchannel: use `TOPICLEN` token from `ISUPPORT` if available
  • Loading branch information
dgw authored Nov 30, 2020
2 parents 9f5116d + 02a53b3 commit 9c8ce47
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions sopel/modules/adminchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

import re

from sopel import formatting, plugin
from sopel.tools import Identifier
from sopel import formatting, plugin, tools


ERROR_MESSAGE_NOT_OP = "I'm not a channel operator!"
Expand Down Expand Up @@ -113,7 +112,7 @@ def kick(bot, trigger):
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
opt = tools.Identifier(text[1])
nick = opt
channel = trigger.sender
reasonidx = 2
Expand Down Expand Up @@ -169,7 +168,7 @@ def ban(bot, trigger):
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
opt = tools.Identifier(text[1])
banmask = opt
channel = trigger.sender
if not opt.is_nick():
Expand Down Expand Up @@ -198,7 +197,7 @@ def unban(bot, trigger):
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
opt = tools.Identifier(text[1])
banmask = opt
channel = trigger.sender
if not opt.is_nick():
Expand Down Expand Up @@ -227,7 +226,7 @@ def quiet(bot, trigger):
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
opt = tools.Identifier(text[1])
quietmask = opt
channel = trigger.sender
if not opt.is_nick():
Expand Down Expand Up @@ -256,7 +255,7 @@ def unquiet(bot, trigger):
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
opt = tools.Identifier(text[1])
quietmask = opt
channel = trigger.sender
if not opt.is_nick():
Expand Down Expand Up @@ -287,7 +286,7 @@ def kickban(bot, trigger):
argc = len(text)
if argc < 4:
return
opt = Identifier(text[1])
opt = tools.Identifier(text[1])
nick = opt
mask = text[2]
channel = trigger.sender
Expand Down Expand Up @@ -334,12 +333,22 @@ def topic(bot, trigger):
args = top.split('~', narg)

if len(args) != narg:
message = "Not enough arguments. You gave {}, it requires {}.".format(
message = "Not enough arguments. You gave {}; it requires {}.".format(
len(args), narg)
bot.reply(message)
return
topic = mask.format(*args)

topiclen = getattr(bot.isupport, 'TOPICLEN', None)
if topiclen is not None:
my_len = len(topic.encode('utf-8'))
if my_len > topiclen:
bot.reply(
"Formatted topic is too long ({} bytes); "
"the server limit is {} bytes."
.format(my_len, topiclen))
return

bot.write(('TOPIC', channel + ' :' + topic))


Expand Down

0 comments on commit 9c8ce47

Please sign in to comment.