Replace rest of bot.config references. Clear record.py of old config usage.

This commit is contained in:
2024-09-03 19:43:37 -04:00
parent 3a47f58382
commit 44586183fe
5 changed files with 24 additions and 33 deletions
+4 -6
View File
@@ -9,13 +9,12 @@ from git import Repo
from nextcord.ext import commands from nextcord.ext import commands
from classes.gitea_webhook import GiteaWebhook from classes.gitea_webhook import GiteaWebhook
from DakinySettings import settings
from utils import REPO_DIR, edit_clan_council_info, update_clan_messages from utils import REPO_DIR, edit_clan_council_info, update_clan_messages
if TYPE_CHECKING: if TYPE_CHECKING:
import nextcord import nextcord
from DakinySettings import DakinySettings
app = FastAPI() app = FastAPI()
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git" REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
@@ -30,7 +29,6 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot self.bot = bot
self.config: DakinySettings = self.bot.config
self.repo_setup() self.repo_setup()
@commands.Cog.listener() @commands.Cog.listener()
@@ -58,13 +56,13 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
channel_updates = {file.split("/")[1] for file in modified_files if file.split("/")[1] not in template_updates} channel_updates = {file.split("/")[1] for file in modified_files if file.split("/")[1] not in template_updates}
self.origin.pull() self.origin.pull()
guild: nextcord.Guild = self.bot.get_guild(self.config.params.guild_id) guild: nextcord.Guild = self.bot.get_guild(settings.params.guild_id)
await update_clan_messages(guild, channel_updates) await update_clan_messages(guild, channel_updates)
# if the council members template has changed, update the message # if the council members template has changed, update the message
if "council_members.txt" in template_updates: if "council_members.txt" in template_updates:
await edit_clan_council_info(self.bot.get_guild(self.config.params.guild_id)) await edit_clan_council_info(self.bot.get_guild(settings.params.guild_id))
return {"message": "Successfully updated all discord messages."} return {"message": "Successfully updated all discord messages."}
@@ -78,7 +76,7 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
self.origin = self.repo.remote("origin") self.origin = self.repo.remote("origin")
if self.config.params.git_branch == "test": if settings.params.git_branch == "test":
self.repo.create_head("test", self.origin.refs.test).set_tracking_branch(self.origin.refs.test).checkout() self.repo.create_head("test", self.origin.refs.test).set_tracking_branch(self.origin.refs.test).checkout()
else: else:
self.repo.create_head("main", self.origin.refs.main).set_tracking_branch(self.origin.refs.main).checkout() self.repo.create_head("main", self.origin.refs.main).set_tracking_branch(self.origin.refs.main).checkout()
+14 -17
View File
@@ -4,7 +4,7 @@ import nextcord
from discord import TextInputStyle from discord import TextInputStyle
from nextcord.ext import commands from nextcord.ext import commands
from DakinySettings import DakinySettings from DakinySettings import settings
from utils import GUILDS, MAX_DISCORD_MESSAGE_LENGTH, record_event_points from utils import GUILDS, MAX_DISCORD_MESSAGE_LENGTH, record_event_points
@@ -42,9 +42,9 @@ class RecordCog(commands.Cog, name="Record Commands"):
host (nextcord.Member, optional): Alternative host to user using command. host (nextcord.Member, optional): Alternative host to user using command.
""" """
# check role # check role
if interaction.guild.get_role(self.bot.config.params.event_host_role_id) not in interaction.user.roles: if interaction.guild.get_role(settings.role_ids.event_host) not in interaction.user.roles:
await interaction.response.send_message( await interaction.response.send_message(
f"You must have the <@&{self.bot.config.params.event_host_role_id}> role to record an event.", f"You must have the <@&{settings.role_ids.event_host}> role to record an event.",
ephemeral=True, ephemeral=True,
) )
return return
@@ -59,7 +59,7 @@ class RecordCog(commands.Cog, name="Record Commands"):
await interaction.response.send_message( await interaction.response.send_message(
"Fill out event details and select all members who participated!", "Fill out event details and select all members who participated!",
view=EventView(name, self.bot.config, host.id), view=EventView(name, host.id),
ephemeral=True, ephemeral=True,
embed=embed, embed=embed,
) )
@@ -105,9 +105,9 @@ class RecordCog(commands.Cog, name="Record Commands"):
non_discord_recipient (str): Non Discord member to give point to. non_discord_recipient (str): Non Discord member to give point to.
""" """
# role check # role check
if interaction.guild.get_role(self.bot.config.params.clan_member_role_id) not in interaction.user.roles: if interaction.guild.get_role(settings.role_ids.clan_member) not in interaction.user.roles:
await interaction.response.send_message( await interaction.response.send_message(
f"You must have the <@&{self.bot.config.params.clan_member_role_id}> role to record points.", f"You must have the <@&{settings.role_ids.clan_member}> role to record points.",
ephemeral=True, ephemeral=True,
) )
return return
@@ -119,14 +119,14 @@ class RecordCog(commands.Cog, name="Record Commands"):
elif recipient is not None: # noqa: RET505 elif recipient is not None: # noqa: RET505
record_event_points( record_event_points(
[str(recipient.id)], [str(recipient.id)],
self.bot.config.params.event_participate_points, settings.event_settings.participate_points,
is_member=True, is_member=True,
) )
recipient_str = f"<@{recipient.id}>" recipient_str = f"<@{recipient.id}>"
elif non_discord_recipient is not None: elif non_discord_recipient is not None:
record_event_points( record_event_points(
[non_discord_recipient], [non_discord_recipient],
self.bot.config.params.event_participate_points, settings.event_settings.participate_points,
is_member=False, is_member=False,
) )
recipient_str = f'"{non_discord_recipient}"' recipient_str = f'"{non_discord_recipient}"'
@@ -134,9 +134,7 @@ class RecordCog(commands.Cog, name="Record Commands"):
await interaction.response.send_message("You must provide a recipient.", ephemeral=True) await interaction.response.send_message("You must provide a recipient.", ephemeral=True)
return return
event_channel: nextcord.TextChannel = interaction.guild.get_channel( event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post)
self.bot.config.params.event_post_channel_id
)
msg = f"<@{interaction.user.id}> has given {recipient_str} points for the {activity} activity. Justification: {justification}" # noqa: E501 msg = f"<@{interaction.user.id}> has given {recipient_str} points for the {activity} activity. Justification: {justification}" # noqa: E501
if not msg.endswith("."): if not msg.endswith("."):
@@ -153,11 +151,10 @@ class EventView(nextcord.ui.View):
Also contains a UserSelect object to pick discord members. Also contains a UserSelect object to pick discord members.
""" """
def __init__(self, name: str, config: DakinySettings, host_id: int): def __init__(self, name: str, host_id: int):
super().__init__() super().__init__()
self.name: str = name self.name: str = name
self.config: DakinySettings = config
self.host_id: int = host_id self.host_id: int = host_id
self.event_participants = ParticipantSelect() self.event_participants = ParticipantSelect()
@@ -188,7 +185,7 @@ class EventView(nextcord.ui.View):
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id] discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id]
record_event_points( record_event_points(
discord_users_list, discord_users_list,
self.config.params.event_participate_points, settings.event_settings.participate_points,
is_member=True, is_member=True,
) )
@@ -197,13 +194,13 @@ class EventView(nextcord.ui.View):
non_discord_users_list: list[str] = non_discord_users.split("\n") non_discord_users_list: list[str] = non_discord_users.split("\n")
record_event_points( record_event_points(
non_discord_users_list, non_discord_users_list,
self.config.params.event_participate_points, settings.event_settings.participate_points,
is_member=False, is_member=False,
) )
record_event_points([self.host_id], self.config.params.event_host_points, is_member=True) record_event_points([self.host_id], settings.event_settings.host_points, is_member=True)
event_channel: nextcord.TextChannel = interaction.guild.get_channel(self.config.params.event_post_channel_id) event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post)
await event_channel.send(embed=interaction.message.embeds[0]) await event_channel.send(embed=interaction.message.embeds[0])
await interaction.response.edit_message(content="Event has been submitted.", view=None, embed=None) await interaction.response.edit_message(content="Event has been submitted.", view=None, embed=None)
+3 -7
View File
@@ -6,11 +6,9 @@ import nextcord
from nextcord.ext import commands from nextcord.ext import commands
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from DakinySettings import settings
from database_setup.sql_data_classes import Presences, engine from database_setup.sql_data_classes import Presences, engine
if TYPE_CHECKING:
from DakinySettings import DakinySettings
class RequestCog(commands.Cog, name="Request Commands"): class RequestCog(commands.Cog, name="Request Commands"):
"""Class holds request commands.""" """Class holds request commands."""
@@ -41,10 +39,9 @@ class RequestCog(commands.Cog, name="Request Commands"):
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
presence (str): The presence to add. presence (str): The presence to add.
""" """
config: DakinySettings = self.bot.config
content = f'<@{interaction.user.id}> would like to add presence "{presence}."' content = f'<@{interaction.user.id}> would like to add presence "{presence}."'
view = PresenceChange(presence) view = PresenceChange(presence)
await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view) await self.bot.get_channel(settings.channel_ids.admin).send(content=content, view=view)
await interaction.response.send_message("Request sent to admins.", ephemeral=True) await interaction.response.send_message("Request sent to admins.", ephemeral=True)
@request.subcommand(description="Request to change your Dakiny nickname") @request.subcommand(description="Request to change your Dakiny nickname")
@@ -65,10 +62,9 @@ class RequestCog(commands.Cog, name="Request Commands"):
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
new_nickname(str): The username to change to. new_nickname(str): The username to change to.
""" """
config: DakinySettings = self.bot.config
content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."' content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."'
view = UsernameRequest(interaction.user.id, new_nickname) view = UsernameRequest(interaction.user.id, new_nickname)
await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view) await self.bot.get_channel(settings.channel_ids.admin).send(content=content, view=view)
await interaction.response.send_message("Request sent to admins.", ephemeral=True) await interaction.response.send_message("Request sent to admins.", ephemeral=True)
+2 -2
View File
@@ -106,8 +106,8 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
Sends a message saying happy cakeday. Sends a message saying happy cakeday.
""" """
today = datetime.now(tz=UTC).date() today = datetime.now(tz=UTC).date()
guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id) guild: nextcord.Guild = self.bot.get_guild(settings.params.guild_id)
announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id) announce_channel: nextcord.TextChannel = guild.get_channel(settings.channel_ids.general)
cakedays: list[nextcord.Member] = [ cakedays: list[nextcord.Member] = [
human for human in guild.humans if human.joined_at.month == today.month and human.joined_at.day == today.day human for human in guild.humans if human.joined_at.month == today.month and human.joined_at.day == today.day
+1 -1
View File
@@ -57,7 +57,7 @@ def main() -> None:
print(f"{bot.user.name} has connected to Discord!") # noqa: T201 TODO make logging to print my stuff to console print(f"{bot.user.name} has connected to Discord!") # noqa: T201 TODO make logging to print my stuff to console
# Run Discord bot # Run Discord bot
bot.run(bot.config.params.discord_token) bot.run(settings.params.discord_token)
if __name__ == "__main__": if __name__ == "__main__":