Get guild data everywhere highscores_data was used.

This commit is contained in:
alwayscompiling
2022-07-22 23:33:11 -04:00
parent d067da2300
commit be29194a57
6 changed files with 49 additions and 32 deletions
+9 -5
View File
@@ -23,14 +23,18 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
@commands.Cog.listener()
async def on_message(self, message: nextcord.Message):
"""Listener for message creation. Adds score and attachments to submission."""
guild_id = message.guild.id
guild_data = highscores_data[str(guild_id)]
if message.author.id in submission_objects:
message_id = submission_objects[message.author.id]["message_id"]
submission_message: nextcord.Message = await self.bot.get_channel(
highscores_data["submission_channel_id"]
).fetch_message(message_id)
submission_message: nextcord.Message = (
self.bot.get_guild(guild_id)
.get_channel(guild_data["submission_channel_id"])
.fetch_message(message_id)
)
# need check if correct user and correct channel
if message.channel.id == highscores_data["submission_channel_id"]:
if message.channel.id == guild_data["submission_channel_id"]:
state = submission_objects[message.author.id]["submission_state"]
if state == SubmissionState.SCORE and message.content:
@@ -75,7 +79,7 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
)
elif state == SubmissionState.NAME and message.content:
submission_objects[message.author.id]["username"] = message.content[
: highscores_data["username_length"]
: highscores_data[guild_id_str]["username_length"]
]
embed = get_submission_embed(message.author.id)
await submission_message.edit(
+2 -1
View File
@@ -29,7 +29,8 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
?post-scores
```
"""
highscore_channel_id = highscores_data["highscore_channel_id"]
guild_data = highscores_data[ctx.guild.id]
highscore_channel_id = guild_data["highscore_channel_id"]
print(f"Printing out highscores information in channel {highscore_channel_id}")
channel = ctx.guild.get_channel(highscore_channel_id)
+4 -3
View File
@@ -29,16 +29,17 @@ class RegisterVerificationChannel(commands.Cog, name="Register"):
"""
# respond to the message
channel_id = ctx.channel.id
guild_data = highscores_data[ctx.guild.id]
if registration_type == "verify":
await ctx.send(f"Registered <#{channel_id}> as channel to post verifications in.")
highscores_data["verification_channel_id"] = channel_id
guild_data["verification_channel_id"] = channel_id
elif registration_type == "highscore":
await ctx.send(f"Registered <#{channel_id}> as channel to post highscores in.")
highscores_data["highscore_channel_id"] = channel_id
guild_data["highscore_channel_id"] = channel_id
elif registration_type == "submission":
await ctx.send(f"Registered <#{channel_id}> as channel to post submissions in.")
highscores_data["submission_channel_id"] = channel_id
guild_data["submission_channel_id"] = channel_id
else:
embed = Embed(
title="Register command help", description="How to use the register command."
+5 -4
View File
@@ -29,11 +29,12 @@ class Score(commands.Cog, name="Score"):
This command still works if you prefer to use it over the ui.
```
"""
verification_channel_id = highscores_data["verification_channel_id"]
channel = self.bot.get_channel(verification_channel_id)
guild_data = highscores_data[ctx.guild.id]
verification_channel_id = guild_data["verification_channel_id"]
channel = ctx.guild.get_channel(verification_channel_id)
error_response = "Registered Verification channel does not exist or was never registered. \
Contact server admins."
error_response = "Registered Verification channel does not exist or was never registered."
error_response += "Contact server admins."
assert channel is not None, await ctx.send(error_response)
verification_string = f"{ctx.author.display_name}:{boss_name}:{category}:{score}"
+11 -8
View File
@@ -7,9 +7,10 @@ import nextcord
from nextcord import Embed
from nextcord.ext import commands
from highscores import highscores_config # pylint: disable=import-error
from highscores import highscores_data # pylint: disable=import-error
from highscores import submission_objects # pylint: disable=import-error
from highscores import highscores_message_map # pylint: disable=import-error
from highscores import submission_objects # pylint: disable=import-error
from .verification_view import VerificationView
@@ -55,9 +56,9 @@ def get_submission_embed(userid: int) -> nextcord.Embed:
def category_select_options(boss_name: str) -> "list[nextcord.SelectOption]":
"""Returns list of categories for a given boss."""
options: "list[nextcord.SelectOption]" = []
boss_dict = highscores_data["tables"][boss_name]
for category in boss_dict["categories"].items():
options.append(nextcord.SelectOption(label=category[0]))
category_list = highscores_config["tables"][boss_name]
for category in category_list:
options.append(nextcord.SelectOption(label=category))
return options
@@ -148,8 +149,8 @@ class SubmitButton(nextcord.ui.Button):
self._bot = bot
async def callback(self, interaction: nextcord.Interaction):
verification_channel_id = highscores_data["verification_channel_id"]
channel = self._bot.get_channel(verification_channel_id)
verification_channel_id = highscores_data[interaction.guild.id]["verification_channel_id"]
channel = interaction.guild.get_channel(verification_channel_id)
error_response = "Registered Verification channel does not exist or was never registered. \
Contact server admins."
@@ -186,8 +187,10 @@ class SubmissionCreateButton(nextcord.ui.View):
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
): # pylint: disable=unused-argument
"""Button for score submission."""
guild_data = highscores_data[interaction.guild.id]
boss_name = highscores_message_map[interaction.guild.id][interaction.message.id]
channel = self._bot.get_channel(highscores_data["submission_channel_id"])
channel = interaction.guild.get_channel(guild_data["submission_channel_id"])
# a user should only have 1 submission active at once.
# submitting with dummy message_id until message created
@@ -199,7 +202,7 @@ class SubmissionCreateButton(nextcord.ui.View):
"score": "",
"category": "",
"username": interaction.user.display_name.split("|")[0][
: highscores_data["username_length"]
: guild_data["username_length"]
],
}