diff --git a/src/cogs/aurora.py b/src/cogs/aurora.py index 376a1b0..1a7ba88 100644 --- a/src/cogs/aurora.py +++ b/src/cogs/aurora.py @@ -24,7 +24,6 @@ class Aurora(commands.Cog): self.notified = datetime(2000, 9, 11) # Used to prevent spamming aurora alerts self.aurora_alarm.start() - self.AURORA_CHANNEL = 747542544291987599 def cog_unload(self): self.bot.logger.info("Unloading cog") @@ -91,7 +90,7 @@ class Aurora(commands.Cog): self.bot.logger.info("aurora_alarm: Fetch forecast") return - channel = self.bot.get_channel(self.AURORA_CHANNEL) + channel = self.bot.get_channel(self.bot.channel_ids.get("aurora")) if not channel: self.bot.logger.warning("aurora_alarm: Failed to get aurora channel") return diff --git a/src/cogs/birthday.py b/src/cogs/birthday.py index 821d031..94986ab 100644 --- a/src/cogs/birthday.py +++ b/src/cogs/birthday.py @@ -78,7 +78,10 @@ class Birthday(commands.Cog): return guild = self.bot.get_guild(self.bot.UIO_GAMING_GUILD_ID) - channel = guild.get_channel(747542544291987597) + channel = guild.get_channel(self.bot.channel_ids.get("general")) if guild else None + if not channel: + self.bot.logger.warning("Could not find the general channel. Check ids.guild and ids.channels.general") + return for birthday in birthdays: try: user = await guild.fetch_member(birthday[0]) @@ -118,7 +121,7 @@ class Birthday(commands.Cog): + "bare har 1% sjanse å få!!!!\nhttps://youtu.be/mOyDlnvZwcg" ) - if user.id == 170506717140877312: + if user.id == self.bot.user_ids.get("dev"): message = ( f"Ett steg nærmere døden i dag broder,,, Iskjhe bra,,, {user.mention}\n\n" + "https://youtu.be/9Fr3oLZnmvc" diff --git a/src/cogs/botinfo.py b/src/cogs/botinfo.py index 4685142..7af0209 100644 --- a/src/cogs/botinfo.py +++ b/src/cogs/botinfo.py @@ -34,7 +34,10 @@ class BotInfo(commands.Cog): """ # Dev user info - dev = await self.bot.fetch_user(170506717140877312) + if dev_id := self.bot.user_ids.get("dev"): + dev = await self.bot.fetch_user(dev_id) + else: + dev = (await self.bot.application_info()).owner # Memory usage process = Process(getpid()) diff --git a/src/cogs/gullkorn.py b/src/cogs/gullkorn.py index 99ced6f..f5e5598 100644 --- a/src/cogs/gullkorn.py +++ b/src/cogs/gullkorn.py @@ -77,7 +77,7 @@ class Gullkorn(commands.Cog): message (discord.Message): Message object to check for triggers to """ - if message.author.bot or message.channel.id != 865970753748074576 or not message.mentions: + if message.author.bot or message.channel.id != self.bot.channel_ids.get("gullkorn") or not message.mentions: return for user in message.mentions: diff --git a/src/cogs/misc.py b/src/cogs/misc.py index a8d337f..2c290bd 100644 --- a/src/cogs/misc.py +++ b/src/cogs/misc.py @@ -92,7 +92,7 @@ class Misc(commands.Cog): bruker = interaction.user # Må jo gi meg selv en stor kuk - if bruker.id == 170506717140877312: + if bruker.id == self.bot.user_ids.get("dev"): dick_size = 69 elif bruker.id == 327207142681608192: dick_size = 1 diff --git a/src/cogs/repeated_messages.py b/src/cogs/repeated_messages.py index ff25132..02c1b40 100644 --- a/src/cogs/repeated_messages.py +++ b/src/cogs/repeated_messages.py @@ -1,6 +1,7 @@ import random from datetime import datetime +import discord from discord.ext import commands from discord.ext import tasks @@ -12,7 +13,6 @@ class RepeatedMessages(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot - self.general_channel = 747542544291987597 # self.fredag.start() # self.mandag.start() @@ -23,6 +23,17 @@ class RepeatedMessages(commands.Cog): # self.mandag.cancel() self.new_year.cancel() + def get_general_channel(self) -> discord.TextChannel | None: + """ + Returns + ---------- + (discord.TextChannel | None): The channel to post repeated messages in. None if it can't be found + """ + + if not (channel := self.bot.get_channel(self.bot.channel_ids.get("general"))): + self.bot.logger.warning("Could not find the general channel. Check ids.channels.general in the config") + return channel + @tasks.loop(time=misc_utils.MIDNIGHT) @misc_utils.log_errors async def fredag(self): @@ -33,8 +44,8 @@ class RepeatedMessages(commands.Cog): if datetime.now().weekday() != 4: return - guild = self.bot.get_guild(self.bot.UIO_GAMING_GUILD_ID) - channel = guild.get_channel(self.general_channel) + if not (channel := self.get_general_channel()): + return videos = [ "https://cdn.discordapp.com/attachments/750052141346979850/851216786259181578/video0.mp4", @@ -64,8 +75,8 @@ class RepeatedMessages(commands.Cog): """ if datetime.now().weekday() != 0: return - guild = self.bot.get_guild(self.bot.UIO_GAMING_GUILD_ID) - channel = guild.get_channel(self.general_channel) + if not (channel := self.get_general_channel()): + return await channel.send( "ENDELIG MANDAG!\n\n" + "https://cdn.discordapp.com/attachments/678396498089738250/1168644637687283762/Snapchat-1787493720.mp4" # noqa: E501 @@ -82,8 +93,8 @@ class RepeatedMessages(commands.Cog): if datetime.now().month != 1 or datetime.now().day != 1: return - guild = self.bot.get_guild(self.bot.UIO_GAMING_GUILD_ID) - channel = guild.get_channel(self.general_channel) + if not (channel := self.get_general_channel()): + return await channel.send("GODT NYTTÅR!\n\nNå, meld dere inn i UiO Gaming igjen <:ThisIsAThreat:874998234072903710>") diff --git a/src/cogs/social_credit.py b/src/cogs/social_credit.py index e453b5a..c40742e 100644 --- a/src/cogs/social_credit.py +++ b/src/cogs/social_credit.py @@ -120,7 +120,7 @@ class SocialCredit(commands.Cog): + "If it is, ignore this." ) return - if not (weeb_role := guild.get_role(803629993539403826)): + if not (weeb_role := guild.get_role(self.bot.role_ids.get("weeb"))): self.bot.logger.warning( "Could not fetch UiO Gaming's weeb role." + "If the bot does not have access to the UiO Gaming server, this function won't work. " @@ -288,7 +288,7 @@ class SocialCredit(commands.Cog): message (discord.Message): The message object """ - if message.channel.id == 754706204349038644: + if message.channel.id == self.bot.channel_ids.get("politics"): await self.social_punishment(message.author.id, 25, "politics") @roll(percent=25) @@ -301,7 +301,7 @@ class SocialCredit(commands.Cog): message (discord.Message): The message object """ - if message.channel.id == 811606213665357824: + if message.channel.id == self.bot.channel_ids.get("member_chat"): await self.social_reward(message.author.id, 10, "member-chat") @roll(percent=50) @@ -381,7 +381,7 @@ class SocialCredit(commands.Cog): """ # This only works in the UiO Gaming server as well - if message.channel.id == 865970753748074576 and message.mentions: + if message.channel.id == self.bot.channel_ids.get("gullkorn") and message.mentions: for mention in message.mentions: await self.social_punishment(mention.id, 10, "gullkorn") diff --git a/src/cogs/starboard_scraper.py b/src/cogs/starboard_scraper.py index 92fd9fe..4c5cc45 100644 --- a/src/cogs/starboard_scraper.py +++ b/src/cogs/starboard_scraper.py @@ -23,7 +23,7 @@ class StarboardScraper(commands.Cog): """ self.bot = bot - self.starboard_channel_id = 757614289812193280 + self.starboard_channel_id = self.bot.channel_ids.get("starboard") self.cursor = self.bot.db_connection.cursor() self.init_db() diff --git a/src/cogs/utils/discord_utils.py b/src/cogs/utils/discord_utils.py index 8da3050..6dfd596 100644 --- a/src/cogs/utils/discord_utils.py +++ b/src/cogs/utils/discord_utils.py @@ -417,7 +417,7 @@ class TempVoiceHelper: # Get the UiO Gaming server's VC category. If the command is not invoked in that server it should still be fine # since the it will return None if not found. - vc_category = interaction.guild.get_channel(747542544291987601) + vc_category = interaction.guild.get_channel(self.bot.channel_ids.get("voice_category")) try: channel = await interaction.guild.create_voice_channel( diff --git a/src/cogs/word_cloud.py b/src/cogs/word_cloud.py index 365ed60..468dccd 100644 --- a/src/cogs/word_cloud.py +++ b/src/cogs/word_cloud.py @@ -498,7 +498,7 @@ class WordCloud(commands.Cog): # Get member role for future channel permission checking # This shouldn't be hard coded but eh - board_member_role = interaction.guild.get_role(779849617651138601) + board_member_role = interaction.guild.get_role(self.bot.role_ids.get("board_member")) # This is horrible but there's a lot of edge cases to handle so spare me pls all_messages = "" diff --git a/src/config/config.yaml.example b/src/config/config.yaml.example index 9b3d3e8..0fbd2e0 100644 --- a/src/config/config.yaml.example +++ b/src/config/config.yaml.example @@ -5,6 +5,23 @@ dev_guild: 747542543750660178 # IANA timezone name. Leave empty to use the system's timezone timezone: Europe/Oslo +# Discord IDs the bot's features rely on. Features whose ID is missing are skipped +ids: + guild: 747542543750660178 + channels: + general: 747542544291987597 + aurora: 747542544291987599 + gullkorn: 865970753748074576 + politics: 754706204349038644 + member_chat: 811606213665357824 + starboard: 757614289812193280 + voice_category: 747542544291987601 + roles: + weeb: 803629993539403826 + board_member: 779849617651138601 + users: + dev: 170506717140877312 + # Bot settings bot: token: diff --git a/src/run.py b/src/run.py index 6dadfad..2d2af42 100644 --- a/src/run.py +++ b/src/run.py @@ -11,7 +11,6 @@ from discord.ext import commands from logger import BotLogger -UIO_GAMING_GUILD_ID = 747542543750660178 DATABASE_RELIANT_COGS = { "birthday.py", "gullkorn.py", @@ -67,7 +66,11 @@ class Bot(commands.Bot): self.mc_rcon_password = config["minecraft"]["rcon_password"] # Fetch misc config values - self.UIO_GAMING_GUILD_ID = UIO_GAMING_GUILD_ID + ids = config.get("ids") or {} + self.UIO_GAMING_GUILD_ID = ids.get("guild") + self.channel_ids = ids.get("channels") or {} + self.role_ids = ids.get("roles") or {} + self.user_ids = ids.get("users") or {} self.guild_id = config.get("dev_guild", self.UIO_GAMING_GUILD_ID) self.config_mode = config.get("config_mode") self.presence = config["bot"].get("presence", {})