fixing blackjack and improving lookup
This commit is contained in:
@ -63,6 +63,7 @@ class EventHandler():
|
||||
self.bot.log(log_message, str(ctx.channel_id), level=25)
|
||||
|
||||
async def on_component(self, ctx: ComponentContext):
|
||||
"""Handle component interaction."""
|
||||
info = decode_id(ctx.custom_id)
|
||||
self.bot.log(f"Component action with info {info}")
|
||||
channel = ctx.channel
|
||||
@ -77,23 +78,22 @@ class EventHandler():
|
||||
)
|
||||
return
|
||||
|
||||
if info[1].lower() == "show":
|
||||
elif info[1].lower() == "show":
|
||||
await self.bot.other.plex.add_show(
|
||||
ctx.origin_message,
|
||||
info[2],
|
||||
not isinstance(channel, discord.DMChannel)
|
||||
)
|
||||
return
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
|
||||
elif info[0].lower() == "hangman" and author == info[2]:
|
||||
if info[1].lower() == "guess":
|
||||
await self.bot.games.hangman.guess(ctx, *info[3:])
|
||||
return
|
||||
|
||||
if info[1].lower() == "end":
|
||||
elif info[1].lower() == "end":
|
||||
await self.bot.games.hangman.stop(ctx, *info[3:])
|
||||
return
|
||||
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
elif info[0].lower() == "connectfour":
|
||||
connect_four = self.bot.games.connect_four
|
||||
if info[1].lower() == "place" and author == info[2]:
|
||||
@ -106,19 +106,16 @@ class EventHandler():
|
||||
ctx.author_id,
|
||||
int(info[8])
|
||||
)
|
||||
return
|
||||
|
||||
if info[1].lower() == "end" and author in [info[2], info[3]]:
|
||||
elif info[1].lower() == "end" and author in [info[2], info[3]]:
|
||||
await connect_four.surrender(
|
||||
ctx, [int(info[2]), int(info[3])], info[4], info[5]
|
||||
)
|
||||
return
|
||||
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
elif info[0].lower() == "blackjack":
|
||||
await self.bot.games.blackjack.decode_interaction(ctx, info[1:])
|
||||
return
|
||||
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
|
||||
|
||||
|
||||
|
@ -139,7 +139,7 @@ class DatabaseFuncs():
|
||||
old_images_path = "gwendolyn/resources/games/old_images/"
|
||||
file_path = old_images_path + f"connect_four{channel.id}"
|
||||
if os.path.isfile(file_path):
|
||||
with open(file_path, "r") as file_pointer:
|
||||
with open(file_path, "r", encoding="utf-8") as file_pointer:
|
||||
old_image = int(file_pointer.read())
|
||||
else:
|
||||
old_image = 0
|
||||
|
@ -109,7 +109,7 @@ def get_options():
|
||||
options: dict
|
||||
The options of the bot.
|
||||
"""
|
||||
with open("options.txt", "r") as file_pointer:
|
||||
with open("options.txt", "r", encoding="utf-8") as file_pointer:
|
||||
data = sanitize(file_pointer.read(), True)
|
||||
|
||||
options = {}
|
||||
@ -128,7 +128,7 @@ def get_credentials():
|
||||
credentials: dict
|
||||
The credentials used by the bot.
|
||||
"""
|
||||
with open("credentials.txt", "r") as file_pointer:
|
||||
with open("credentials.txt", "r", encoding="utf-8") as file_pointer:
|
||||
data = sanitize(file_pointer.read())
|
||||
|
||||
credentials = {}
|
||||
@ -155,7 +155,8 @@ def long_strings():
|
||||
data: dict
|
||||
The long strings and their keys.
|
||||
"""
|
||||
with open("gwendolyn/resources/long_strings.json", "r") as file_pointer:
|
||||
long_strings_path = "gwendolyn/resources/long_strings.json"
|
||||
with open(long_strings_path, "r", encoding="utf-8") as file_pointer:
|
||||
data = json.load(file_pointer)
|
||||
|
||||
return data
|
||||
@ -170,7 +171,8 @@ def get_params():
|
||||
params: dict
|
||||
The parameters for every slash command.
|
||||
"""
|
||||
with open("gwendolyn/resources/slash_parameters.json", "r") as file_pointer:
|
||||
path = "gwendolyn/resources/slash_parameters.json"
|
||||
with open(path, "r", encoding="utf-8") as file_pointer:
|
||||
slash_parameters = json.load(file_pointer)
|
||||
|
||||
options = get_options()
|
||||
@ -256,14 +258,14 @@ def make_files():
|
||||
"""Create json file if it doesn't exist."""
|
||||
if not os.path.isfile(path):
|
||||
log_this(path.split("/")[-1]+" didn't exist. Making it now.")
|
||||
with open(path, "w") as file_pointer:
|
||||
with open(path, "w", encoding="utf-8") as file_pointer:
|
||||
json.dump(content, file_pointer, indent=4)
|
||||
|
||||
def make_txt_file(path, content):
|
||||
"""Create txt file if it doesn't exist."""
|
||||
if not os.path.isfile(path):
|
||||
log_this(path.split("/")[-1]+" didn't exist. Making it now.")
|
||||
with open(path, "w") as file_pointer:
|
||||
with open(path, "w", encoding="utf-8") as file_pointer:
|
||||
file_pointer.write(content)
|
||||
|
||||
def directory(path):
|
||||
@ -272,7 +274,8 @@ def make_files():
|
||||
os.makedirs(path)
|
||||
log_this("The "+path.split("/")[-1]+" directory didn't exist")
|
||||
|
||||
with open("gwendolyn/resources/starting_files.json") as file_pointer:
|
||||
file_path = "gwendolyn/resources/starting_files.json"
|
||||
with open(file_path, "r", encoding="utf-8") as file_pointer:
|
||||
data = json.load(file_pointer)
|
||||
|
||||
for path, content in data["json"].items():
|
||||
|
Reference in New Issue
Block a user