kurisu.py: Move loading roles and channels to their own class methods and reorder code
# license: Apache License 2.0
# https://github.com/nh-server/Kurisu
+import os
from asyncio import Event
from configparser import ConfigParser
+from datetime import datetime
from subprocess import check_output, CalledProcessError
-import os
-from utils.database import ConnectionHolder
from sys import exit, hexversion
from traceback import format_exception, format_exc
+
import discord
from discord.ext import commands
-from datetime import datetime
+
from utils.checks import check_staff_id
+from utils.database import ConnectionHolder
# sets working directory to bot's folder
dir_path = os.path.dirname(os.path.realpath(__file__))
@@ -152,6 +154,18 @@ class Kurisu(commands.Bot):
print(f'{extension} failed to load.')
self.failed_cogs.append([extension, type(e).__name__, e])
+ def load_channels(self):
+ for n in self.channels.keys():
+ self.channels[n] = discord.utils.get(self.guild.channels, name=n)
+ if not self.channels[n]:
+ print(f'Failed to find channel {n}')
+
+ def load_roles(self):
+ for n in self.roles.keys():
+ self.roles[n] = discord.utils.get(self.guild.roles, name=n)
+ if not self.roles[n]:
+ print(f'Failed to find role {n}')
+
@staticmethod
def escape_text(text):
text = str(text)
@@ -162,15 +176,8 @@ class Kurisu(commands.Bot):
assert len(guilds) == 1
self.guild = guilds[0]
- for n in self.channels.keys():
- self.channels[n] = discord.utils.get(self.guild.channels, name=n)
- if not self.channels[n]:
- print(f'Failed to find channel {n}')
-
- for n in self.roles.keys():
- self.roles[n] = discord.utils.get(self.guild.roles, name=n)
- if not self.roles[n]:
- print(f'Failed to find role {n}')
+ self.load_channels()
+ self.load_roles()
self.assistance_channels = {
self.channels['3ds-assistance-1'],
