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

Commit

Permalink
Reduce verbosity of advance logger
Browse files Browse the repository at this point in the history
  • Loading branch information
KOOKIIEStudios committed Nov 9, 2020
1 parent 886b226 commit b3b1bd7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
14 changes: 7 additions & 7 deletions src/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class API:

@staticmethod
def get_server_info():
spirit_logger.debug("Attempting to fetch server info via API")
# spirit_logger.debug("Attempting to fetch server info via API")
try:
payload = {
"key": config.API_KEY
Expand All @@ -29,7 +29,7 @@ def get_server_info():

@staticmethod
def dc_player(name):
spirit_logger.debug("Attempting to disconnecting player via API")
# spirit_logger.debug("Attempting to disconnecting player via API")
try:
payload = {
"key": config.API_KEY,
Expand All @@ -52,7 +52,7 @@ def bot_check(name):

@staticmethod
def whisper(name, message):
spirit_logger.debug("Attempting to whisper via API")
# spirit_logger.debug("Attempting to whisper via API")
try:
payload = {
"key": config.API_KEY,
Expand All @@ -71,7 +71,7 @@ def whisper(name, message):

@staticmethod
def notice(message):
spirit_logger.debug("Attempting to send in-game notice via API")
# spirit_logger.debug("Attempting to send in-game notice via API")
try:
payload = {
"key": config.API_KEY,
Expand All @@ -89,7 +89,7 @@ def notice(message):

@staticmethod
def duey(item, amount, name):
spirit_logger.debug("Attempting to send item(s) in-game via API")
# spirit_logger.debug("Attempting to send item(s) in-game via API")
try:
payload = {
"key": config.API_KEY,
Expand All @@ -109,7 +109,7 @@ def duey(item, amount, name):

@staticmethod
def set_gm_level(name, level):
spirit_logger.debug("Attempting to set GM level via API")
# spirit_logger.debug("Attempting to set GM level via API")
try:
payload = {
"key": config.API_KEY,
Expand All @@ -128,7 +128,7 @@ def set_gm_level(name, level):

@staticmethod
def give_vp(name, amount):
spirit_logger.debug("Attempting to allocate vote points in-game via API")
# spirit_logger.debug("Attempting to allocate vote points in-game via API")
try:
payload = {
"key": config.API_KEY,
Expand Down
9 changes: 8 additions & 1 deletion src/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ async def handle_credits(client, txt_channel, author, msg, message) \
# -> "Give items through Duey":
# args = msg.split(" ")
# if len(args) <= 4:
# # spirit_logger.warn(f"{author} has made and invalid !duey command attempt: {msg}")
# await txt_channel.send("Usage: !duey <name> <item> <quantity>")
# return False
# s = API.duey(amount=1, name="Desc")
Expand All @@ -278,6 +279,7 @@ async def handle_dc(client, txt_channel, author, msg, message) \
-> "DC a player":
args = msg.split(" ")
if len(args) < 2:
# spirit_logger.warn(f"{author} has made and invalid !dc command attempt: {msg}")
await txt_channel.send("Usage: !dc <character>")
return False
player = args[1]
Expand All @@ -295,6 +297,7 @@ async def handle_whisper(client, txt_channel, author, msg, message) \
-> "Whisper a player in game":
args = msg.split(" ")
if len(args) < 2:
# spirit_logger.warn(f"{author} has made and invalid !whisper command attempt: {msg}")
await txt_channel.send("Usage: !whisper <name> <message>")
return False
player = args[1]
Expand All @@ -317,6 +320,7 @@ async def handle_notice(client, txt_channel, author, msg, message) \
-> "Send a message to all players":
args = msg.split(" ")
if len(args) <= 1:
# spirit_logger.warn(f"{author} has made and invalid !notice command attempt: {msg}")
await txt_channel.send("Usage: !notice <message>")
return False
i = 1
Expand All @@ -338,6 +342,7 @@ async def handle_unban(client, txt_channel, author, msg, message) \
-> "Unbans a player":
args = msg.split(" ")
if len(args) < 2:
# spirit_logger.warn(f"{author} has made and invalid !unban command attempt: {msg}")
await txt_channel.send("Usage: !unban <player>")
return False
player = args[1]
Expand All @@ -356,6 +361,7 @@ async def handle_setgmlevel(client, txt_channel, author, msg, message) \

args = msg.split(" ")
if len(args) < 3:
# spirit_logger.warn(f"{author} has made and invalid !getgmlevel command attempt: {msg}")
await txt_channel.send("Usage: !setgmlevel <player> <level>")
return False
player = args[1]
Expand All @@ -380,7 +386,8 @@ async def handle_give_vp(client, txt_channel, author, msg, message) \

args = msg.split(" ")
if len(args) < 3:
await txt_channel.send("Usage: !givevp <name> <amount>")
# await txt_channel.send("Usage: !givevp <name> <amount>")
spirit_logger.warn(f"{author} has made and invalid !givevp command attempt: {msg}")
return False
player = args[1]
vp = int(args[2])
Expand Down
12 changes: 6 additions & 6 deletions src/commands/command_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ async def wrapper(*args, **kwargs_wrap):
spirit_logger.debug(f"author: {author}; msg: {msg}")
for key, value in kwargs.items():

spirit_logger.debug(f"Key: {key}; Value: {value}")
# spirit_logger.debug(f"Key: {key}; Value: {value}")
# Command name check
# Check if the start of the message matches the command aliases defined in the decorator
# If not, don't carry out (i.e. empty return)
if "cmd" in key:
# Sanity check - for single String command name (never used, as far as I can tell)
spirit_logger.debug("Performing command name check")
# spirit_logger.debug("Performing command name check")
if isinstance(value, str):
c = "{}{}".format(config.PREFIX, value)
if not msg.startswith(c):
Expand All @@ -48,15 +48,15 @@ async def wrapper(*args, **kwargs_wrap):
# Toggle status check - KOOKIIE
if "toggle" in key:
# Sanity check - make sure it's of Boolean type
spirit_logger.debug("Performing toggle status check")
# spirit_logger.debug("Performing toggle status check")
if isinstance(value, bool):
if not value: # if toggle status is false
await txt_channel.send(config.DISABLED_TEXT) # send out error message, and don't carry out
return

# Role checks
if "role" in key: # Role the author must have for the command to be executed
spirit_logger.debug("Performing role check")
# spirit_logger.debug("Performing role check")
if isinstance(value, str):
if not author.roles == value:
return
Expand All @@ -72,7 +72,7 @@ async def wrapper(*args, **kwargs_wrap):

# Excluding Channel checks
elif "excl_channel" in key: # Channel(s) command is not allowed in.
spirit_logger.debug("Performing channel exclusion check")
# spirit_logger.debug("Performing channel exclusion check")
if isinstance(value, str):
if txt_channel.get_channel_name() == value:
return
Expand All @@ -87,7 +87,7 @@ async def wrapper(*args, **kwargs_wrap):

# Channel checks
elif "channel" in key: # Channel(s) command must be in.
spirit_logger.debug("Performing channel inclusion check")
# spirit_logger.debug("Performing channel inclusion check")
if isinstance(value, str):
if not txt_channel.get_channel_name() == value:
return
Expand Down
31 changes: 16 additions & 15 deletions src/database_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DatabaseHandler:
@staticmethod
def get_character_stats(character_name):
try:
spirit_logger.debug(f"Attempting to get char stats from name via DB: {character_name}")
# spirit_logger.debug(f"Attempting to get char stats from name via DB: {character_name}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -31,7 +31,7 @@ def get_character_stats(character_name):
@staticmethod
def get_character_look(character_id, hair, face, skin):
try:
spirit_logger.debug(f"Attempting to get char look via DB. ID: {character_id}; Hair: {hair}; Face: {face}; Skin: {skin}")
# spirit_logger.debug(f"Attempting to get char look via DB. ID: {character_id}; Hair: {hair}; Face: {face}; Skin: {skin}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -54,10 +54,11 @@ def get_character_look(character_id, hair, face, skin):

@staticmethod
def get_guild_name(guild_id):
if guild_id == 0: # Guildless
if guild_id == 0: # No guild
# spirit_logger.debug("Invalid guild")
return "None"
try:
spirit_logger.debug(f"Attempting to get guild name from id: {guild_id}")
# spirit_logger.debug(f"Attempting to get guild name from id: {guild_id}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -76,7 +77,7 @@ def get_guild_name(guild_id):
@staticmethod
def get_guild_info(name):
try:
spirit_logger.debug(f"Attempting to get guild info from id: {guild_id}")
# spirit_logger.debug(f"Attempting to get guild info from id: {guild_id}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -92,9 +93,9 @@ def get_guild_info(name):

@staticmethod
def get_alliance_name(alliance_id):
spirit_logger.debug(f"Attempting to get alliance info from id: {alliance_id}")
# spirit_logger.debug(f"Attempting to get alliance info from id: {alliance_id}")
if alliance_id == 0:
spirit_logger.debug("Invalid ID")
# spirit_logger.debug("Invalid alliance")
return "None"
else:
try:
Expand All @@ -115,7 +116,7 @@ def get_alliance_name(alliance_id):
@staticmethod
def get_character_name(char_id):
try:
spirit_logger.debug(f"Attempting to get character name from id: {char_id}")
# spirit_logger.debug(f"Attempting to get character name from id: {char_id}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -133,7 +134,7 @@ def get_character_name(char_id):
@staticmethod
def get_account_id(character_name):
try:
spirit_logger.debug(f"Attempting to get account ID from character name: {character_name}")
# spirit_logger.debug(f"Attempting to get account ID from character name: {character_name}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -153,7 +154,7 @@ def get_account_id(character_name):
@staticmethod
def unban_account(name):
try:
spirit_logger.debug(f"Attempting to unban account by name: {name}")
# spirit_logger.debug(f"Attempting to unban account by name: {name}")
account_id = DatabaseHandler.get_account_id(name) # Don't use "id" as it is reserved by Python
if not account_id: # checks if id is false which means the character was not found
return f"Couldn't find {name}"
Expand All @@ -180,7 +181,7 @@ def get_rankings(category):
Return: dict, boolean
"""
try:
spirit_logger.debug(f"Attempting to get rankings by category: {category}")
# spirit_logger.debug(f"Attempting to get rankings by category: {category}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -197,7 +198,7 @@ def get_rankings(category):
@staticmethod
def get_vp(account_id):
try:
spirit_logger.debug(f"Attempting to get vote points by id: {account_id}")
# spirit_logger.debug(f"Attempting to get vote points by id: {account_id}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -215,7 +216,7 @@ def get_vp(account_id):
@staticmethod
def give_vp(name, amount):
try:
spirit_logger.debug(f"Attempting to allocate {amount} vote points by name: {name}")
# spirit_logger.debug(f"Attempting to allocate {amount} vote points by name: {name}")
account_id = DatabaseHandler.get_account_id(name)
if not account_id:
return f"Character {name} not found"
Expand All @@ -237,7 +238,7 @@ def give_vp(name, amount):
@staticmethod
def get_gm_level(name):
try:
spirit_logger.debug(f"Attempting to get GM level by name: {name}")
# spirit_logger.debug(f"Attempting to get GM level by name: {name}")
con = mysql.connector.connect(host=config.DATABASE_HOST, user=config.DATABASE_USER,
password=config.DATABASE_PASS, database=config.DATABASE_NAME)
cursor = con.cursor(dictionary=True)
Expand All @@ -259,7 +260,7 @@ def get_gm_level(name):
@staticmethod
def set_gm_level(name, level):
try:
spirit_logger.debug(f"Attempting to set GM level to {level} by name: {name}")
# spirit_logger.debug(f"Attempting to set GM level to {level} by name: {name}")
lvl = DatabaseHandler.get_gm_level(name)
if lvl is False:
return f"Character {name} not found"
Expand Down

0 comments on commit b3b1bd7

Please sign in to comment.