Exemple #1
0
def get_extension_by_name(name):
    extension = EXTENSION_LOADER.get_extension(name)
    if (extension is None):
        abort('There is no extension with the specified name.')

    if extension.locked:
        abort('The extension is locked, probably for reason.')

    return extension
Exemple #2
0
async def register(
        event,
        name: ('str', 'Please provide a name to register.'),
):
    """Registers the specified extension by it's name."""
    check_permission(event)

    extension = EXTENSION_LOADER.get_extension(name)
    if (extension is not None):
        abort(
            f'There is already an extension added with the given name: `{extension.name}`.'
        )

    try:
        EXTENSION_LOADER.add(name)
    except TypeError:
        title = f'Registering {name!r} extension failed.'
        description = 'There is no such extension.'
    else:
        title = f'Registering {name!r} was successful.'
        description = None

    return Embed(title, description)
Exemple #3
0
async def unload(
        event,
        name: ('str', 'Please provide a name to unload.'),
):
    """Unloads the specified extension by it's name."""
    check_permission(event)
    extension = get_extension_by_name(name)

    yield
    name = extension.name
    yield await run_extension_coroutine(
        name,
        'unload',
        EXTENSION_LOADER.unload(name),
    )
Exemple #4
0
from dotenv import dotenv_values
from hata import Client, wait_for_interruption
from hata.ext.extension_loader import EXTENSION_LOADER

config = dotenv_values('.env')

Sakuya = Client(
    config['TOKEN'],
    extensions='commands_v2',
    prefix='!',
)


@Sakuya.events
async def ready(client):
    print(f'{client:f} is connected!')


# Registered variables to extension loader, show up in each loaded extension file.
EXTENSION_LOADER.add_default_variables(Sakuya=Sakuya)
# Adds the extensions file or the extensions files recursive in the folder
EXTENSION_LOADER.add('modules')
# Loads all the added extension files.
EXTENSION_LOADER.load_all()

Sakuya.start()

wait_for_interruption()
Exemple #5
0
from os.path import join as join_path, isdir as is_folder, isfile as is_file
from os import listdir as list_directory

import config

from hata import Client, ActivityRich, ACTIVITY_TYPES
from hata.ext.extension_loader import EXTENSION_LOADER
from bot_utils.shared import PATH__KOISHI

from bot_utils.shared import category_name_rule, DEFAULT_CATEGORY_NAME, PREFIX__MARISA, PREFIX__FLAN, PREFIX__SATORI

MARISA_MODE = config.MARISA_MODE
EXTENSION_LOADER.add_default_variables(MARISA_MODE=MARISA_MODE)

if MARISA_MODE:
    Marisa = Client(
        config.MARISA_TOKEN,
        client_id=config.MARISA_ID,
        http_debug_options='canary',
        extensions=('command_utils', 'slash', 'commands_v2'),
        prefix=PREFIX__MARISA,
        default_category_name=DEFAULT_CATEGORY_NAME,
        category_name_rule=category_name_rule,
    )

    EXTENSION_LOADER.add_default_variables(Marisa=Marisa,
                                           COMMAND_CLIENT=Marisa,
                                           SLASH_CLIENT=Marisa)

    EXTENSION_LOADER.load_extension('bots.marisa', locked=True)
Exemple #6
0
import os

from hata import Client, start_clients
from hata.ext.slash import setup_ext_slash
from hata.ext import asyncio as hata_asyncio  # noqa
from hata.ext.commands import setup_ext_commands
from hata.ext.extension_loader import EXTENSION_LOADER

from database_handler import DatabaseHandler

braindead = Client("YOUR_TOKEN_HERE")
setup_ext_commands(braindead, "!")
setup_ext_slash(braindead)


@braindead.events
async def ready(client):
    print(f"{client:f} logged in.")


EXTENSION_LOADER.add_default_variables(braindead=braindead)

for name in os.listdir("modules"):
    if name.endswith(".py"):
        EXTENSION_LOADER.add(f"modules.{name[:-3]}")

braindead.loop.run(DatabaseHandler.create_connection())
EXTENSION_LOADER.load_all()
start_clients()
Exemple #7
0
# -*- coding: utf-8 -*-
import os

import config

from hata import Client, start_clients, ActivityRich, ActivityTypes
from hata.ext.extension_loader import EXTENSION_LOADER
from bot_utils.shared import KOISHI_PATH

MARISA_MODE = config.MARISA_MODE

EXTENSION_LOADER.add_default_variables(MARISA_MODE=MARISA_MODE)

if MARISA_MODE:
    Marisa = Client(
        config.MARISA_TOKEN,
        client_id=config.MARISA_ID,
    )

    EXTENSION_LOADER.add_default_variables(Marisa=Marisa, main_client=Marisa)

    EXTENSION_LOADER.load_extension('bots.marisa', locked=True)

    EXTENSION_LOADER.add('bots.testers.test_commands')
    EXTENSION_LOADER.add('bots.testers.ratelimit')
    EXTENSION_LOADER.add('bots.testers.dispatch_tests')

else:
    Koishi = Client(
        config.KOISHI_TOKEN,
        secret=config.KOISHI_SECRET,
               status="dnd",
               activity=ActivityRich("The Server",
                                     type_=ActivityTypes.watching))

MELON_MINT = Client(token=config.MELON_MINT_TOKEN,
                    client_id=config.MELON_MINT_ID,
                    status='idle',
                    activity=ActivityRich("My Creator",
                                          type_=ActivityTypes.watching))

#Connecting to database
MELON_MINT.loop.run(My_Database.setup_firebase(config.FIREBASE_CONFIG))

EXTENSION_LOADER.add_default_variables(
    MINT=MINT,
    MELON=MELON,
    MELON_MINT=MELON_MINT,
)

EXTENSION_LOADER.load_extension('bots.mint', locked=True)
EXTENSION_LOADER.load_extension('bots.melon', locked=True)
EXTENSION_LOADER.load_extension('bots.melon_mint', locked=True)

path = os.path.abspath('.')
for folder_name in os.listdir(path):

    if not folder_name.endswith('_modules'):
        continue

    folder_path = os.path.join(path, folder_name)
    for file_name in os.listdir(folder_path):