3
0
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:
James Lu 2019-02-07 13:49:38 -08:00
parent 23cb7c173a
commit 61c8677802
3 changed files with 8 additions and 5 deletions

View File

@ -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):

View File

@ -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:]

View File

@ -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)