mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +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,6 +1410,7 @@ 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
|
||||
if isinstance(target, str):
|
||||
while target and target[0] in avail_prefixes:
|
||||
prefixes.append(avail_prefixes[target[0]])
|
||||
target = target[1:]
|
||||
|
@ -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