Skip to content

Commit

Permalink
Merge pull request #283 from iyad-f/extensions
Browse files Browse the repository at this point in the history
feature to manage what extensions to not load
  • Loading branch information
hitblast authored Oct 8, 2024
2 parents becfa7c + d1e9b20 commit 0776b4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions cogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pkgutil import walk_packages

EXTENTIONS = set(
module.name for module in walk_packages(__path__, f'{__package__}.')
)
16 changes: 13 additions & 3 deletions core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

# Imports.
import asyncio
from typing import List
from typing import Optional, Set

import disnake
from disnake.ext import commands

from cogs import EXTENTIONS
from core.chain import keychain


Expand All @@ -18,10 +19,19 @@ class IgKnite(commands.AutoShardedInteractionBot):
Basically works as the core class for all-things IgKnite!
"""

def __init__(self, *args, initial_extensions: List[str], **kwargs) -> None:
def __init__(
self, *args, ignored_extensions: Optional[Set[str]] = None, **kwargs
) -> None:
super().__init__(*args, **kwargs)

for extension in initial_extensions:
to_load = EXTENTIONS
if ignored_extensions is not None:
# ignored_extensions need's to be a set, can add a check
# but not worth it since these are gonna be passed by a
# developer
to_load -= ignored_extensions

for extension in to_load:
self.load_extension(extension)

async def _update_presence(self) -> None:
Expand Down
9 changes: 1 addition & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
# Set up an instance of IgKnite.
bot = core.IgKnite(
intents=disnake.Intents.all(),
initial_extensions=[
'cogs.customization',
'cogs.exceptionhandler',
'cogs.general',
'cogs.inspection',
'cogs.moderation',
# 'cogs.music', // load this cog if you want to use the music commands
],
ignored_extensions={'cogs.music'}, # lets say we dont wanna load music.py
)


Expand Down

0 comments on commit 0776b4d

Please sign in to comment.