Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Add ASCII checker in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
KOOKIIEStudios committed Nov 9, 2020
1 parent 9bb4bb0 commit 886b226
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Utils:

@staticmethod
def get_ordinal_number(num):
spirit_logger.debug("Getting ordinal number")
# spirit_logger.debug("Getting ordinal number")
SUFFIXES = {1: 'st', 2: 'nd', 3: 'rd'}
if 10 <= num % 100 <= 20:
suffix = 'th'
Expand All @@ -22,7 +22,7 @@ def get_ordinal_number(num):
@staticmethod
def get_job_by_id(id):
try:
spirit_logger.debug("Getting job by ID")
# spirit_logger.debug("Getting job by ID")
with open("settings/jobs.json", "r") as json_file:
data = json.load(json_file)
job_name = data[str(id)]
Expand All @@ -34,7 +34,7 @@ def get_job_by_id(id):

@staticmethod
def get_guild_logo(guild_mark_id, guild_mark_color_id, guild_background_id, guild_background_color_id):
spirit_logger.debug("Getting guild logo")
# spirit_logger.debug("Getting guild logo")
url = f"https://maplestory.io/api/{config.REGION}/{config.VERSION}/GuildMark/background/{guild_background_id}/{guild_background_color_id}/mark/{guild_mark_id}/{guild_mark_color_id}"
spirit_logger.debug(f"Guild logo: {url}")
return url
Expand All @@ -52,10 +52,22 @@ def is_command(cmd):
cmd: string
Return: boolean
"""
spirit_logger.debug("Checking if command should be logged")
# spirit_logger.debug("Checking if command should be logged")
for command in config.COMMANDS:
if cmd == config.PREFIX + command:
spirit_logger.debug(f"{cmd} should be logged")
return True
spirit_logger.debug(f"{cmd} should not be logged")
return False

# Workaround because String.isascii() was only introduced in Python 3.7
@staticmethod
def is_ascii(string):
try:
string.encode('ascii')
except UnicodeEncodeError:
spirit_logger.debug(f"The string {string} is not ASCII")
return False
else:
spirit_logger.debug(f"The string {string} is indeed ASCII")
return True

0 comments on commit 886b226

Please sign in to comment.