mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 13:09:23 +01:00
classes, relay_clientbot: more type safety for protocols/discord
This commit is contained in:
parent
23cb7c173a
commit
61c8677802
@ -725,7 +725,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
|
||||
@functools.lru_cache(maxsize=8192)
|
||||
def to_lower(self, text):
|
||||
if not text:
|
||||
if (not text) or (not isinstance(text, str)):
|
||||
return text
|
||||
if self.casemapping == 'rfc1459':
|
||||
text = text.replace('{', '[')
|
||||
@ -754,7 +754,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||
def _isASCII(s):
|
||||
"""Returns whether the given string only contains non-whitespace ASCII characters."""
|
||||
chars = string.ascii_letters + string.digits + string.punctuation
|
||||
return all(char in chars for char in s)
|
||||
return all(char in chars for char in str(s))
|
||||
|
||||
@classmethod
|
||||
def is_server_name(cls, s):
|
||||
|
@ -1410,9 +1410,10 @@ def handle_messages(irc, numeric, command, args):
|
||||
avail_prefixes = {v: k for k, v in irc.prefixmodes.items()}
|
||||
prefixes = []
|
||||
# Split up @#channel prefixes and the like into their prefixes and target components
|
||||
while target and target[0] in avail_prefixes:
|
||||
prefixes.append(avail_prefixes[target[0]])
|
||||
target = target[1:]
|
||||
if isinstance(target, str):
|
||||
while target and target[0] in avail_prefixes:
|
||||
prefixes.append(avail_prefixes[target[0]])
|
||||
target = target[1:]
|
||||
|
||||
log.debug('(%s) relay.handle_messages: splitting target %r into prefixes=%r, target=%r',
|
||||
irc.name, args['target'], prefixes, target)
|
||||
|
@ -26,6 +26,8 @@ def color_text(s):
|
||||
"""
|
||||
Returns a colorized version of the given text based on a simple hash algorithm.
|
||||
"""
|
||||
if not s:
|
||||
return s
|
||||
colors = ('03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '15')
|
||||
hash_output = hash(s.encode())
|
||||
num = hash_output % len(colors)
|
||||
|
Loading…
Reference in New Issue
Block a user