Skip to content

Commit

Permalink
Tweaks and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LilbabxJJ-1 committed May 10, 2024
1 parent ffa870e commit aefc23e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions CharmCord/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def find_bracket_pairs(entry: str, functions: FunctionHandler, context) ->
return
if code.strip().lower().startswith("$onlyif") and line != 1:
raise SyntaxError("$OnlyIf should only be at the beginning of a command")
if code.strip().lower().startswith("$EndIf"):
if code.strip().lower().startswith("$endif"):
continue
elif code.strip().lower().startswith("$elif"):
if not any("$if" in Char.lower() for Char in test):
Expand All @@ -195,7 +195,7 @@ async def find_bracket_pairs(entry: str, functions: FunctionHandler, context) ->
else:
if code.strip().lower().startswith("$elif"):
end_if = True
elif code.strip().lower().startswith("$EndIf"):
elif code.strip().lower().startswith("$endif"):
end_if = True
continue
else:
Expand All @@ -219,14 +219,10 @@ async def find_bracket_pairs(entry: str, functions: FunctionHandler, context) ->
if first is not None and last is not None and balance1 == 0:
break
count += 1

argument = str(code[first + 1: last])
keyword = code[0:first]
find = [first, last, keyword, argument, context]
func_job = False
while "[" in str(argument) and "]" in str(argument) and "$" in str(argument):
if "$charmai" in argument.lower():
func_job = True
count = 0
start = None
end = None
Expand Down Expand Up @@ -264,25 +260,25 @@ async def find_bracket_pairs(entry: str, functions: FunctionHandler, context) ->
return
if find[2].lower() == "$if" and response is False:
end_if = False
if not any("$EndIf" in Char.lower() for Char in test):
if not any("$endif" in Char.lower() for Char in test):
raise SyntaxError("No $EndIf found in command after $If")
elif find[2].lower() == "$if":
if not any("$EndIf" in Char.lower() for Char in test):
if not any("$endif" in Char.lower() for Char in test):
raise SyntaxError("No $EndIf found in command after $If")

continue
if find[2].lower() == "$elif" and end_if is False:
if not any("$if" in Char.lower() for Char in test):
raise SyntaxError("No $If found in command before $ElIf")

if not any("$EndIf" in Char.lower() for Char in test):
if not any("$endif" in Char.lower() for Char in test):
raise SyntaxError("No $EndIf found in command after $Elif")

if find[2].lower() == "$elif":
if not any("$if" in Char.lower() for Char in test):
raise SyntaxError("No $If found in command before $ElIf")

if not any("$EndIf" in Char.lower() for Char in test):
if not any("$endif" in Char.lower() for Char in test):
raise SyntaxError("No $EndIf found in command after $Elif")

end_if = response is not False
Expand Down
2 changes: 1 addition & 1 deletion CharmCord/utils/Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Commands:

@staticmethod
def command(name: str, code: str, aliases: list, bot=None):
def command(name: str, code: str, aliases: list = [], bot=None):
# Define command function dynamically

@bot.command(name=name, aliases=aliases)
Expand Down

0 comments on commit aefc23e

Please sign in to comment.