async def extensions(self, ctx):

        # create output embeds
        embed_loaded = discord.Embed(colour=discord.Colour.green(),
                                     title=_("loaded extensions"))
        embed_unloaded = discord.Embed(colour=discord.Colour.red(),
                                       title=_("unloaded extensions"))

        # get loaded extension
        loaded_extensions = Extension.loaded()
        if loaded_extensions:
            for extension in loaded_extensions:
                embed_loaded.add_field(name=extension.name,
                                       value=extension.description,
                                       inline=False)
        else:
            embed_loaded.add_field(name=_("no extensions"),
                                   value=_("no extensions loaded"),
                                   inline=False)

        # get unloaded extension
        unloaded_extensions = Extension.unloaded()
        if unloaded_extensions:
            for extension in unloaded_extensions:
                embed_unloaded.add_field(name=extension.name,
                                         value=_(extension.description),
                                         inline=False)
        else:
            embed_unloaded.add_field(name=_("no extensions"),
                                     value=_("no extensions unloaded"),
                                     inline=False)

        # send embeds
        await ctx.send(embed=embed_loaded)
        await ctx.send(embed=embed_unloaded)
    async def load(self, ctx, extension: str):
        extension = extension.lower()

        # check if extension is not on blocklist
        if extension not in self.extensions_blocklist:

            # try to load extension
            try:
                # load extension
                self.bot.load_extension(self.extensions_dir + extension)

                # check extension in database and update/set
                db_extension = Extension.get(extension)
                if db_extension:
                    db_extension.isLoaded = True
                    db_extension.loadMeta()
                else:
                    extension_object = Extension(extension, True)
                    extension_object.loadMeta()
                    db_session.add(extension_object)

                # commit update
                db_session.commit()

            except Exception as e:
                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'"{extension}" wurde nicht aktiviert!')
                embed.add_field(name="Fehler",
                                value="{}: {}".format(type(e).__name__, e),
                                inline=False)

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)
            else:
                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.green(),
                    title=f'"{extension}" wurde erfolgreich aktiviert!')
                # send embed
                await ctx.send(ctx.author.mention, embed=embed)
        else:
            # create output embed
            embed = discord.Embed(
                colour=discord.Colour.red(),
                title=f'"{extension}" wurde nicht aktiviert!')
            embed.add_field(
                name="Fehler",
                value=
                "Die Erweiterung steht auf der Blockliste und darf nicht aktiviert werden.",
                inline=False)

            # send embed
            await ctx.send(ctx.author.mention, embed=embed)
    async def load(self, ctx, extension: str):
        # prepare extension string
        extension = extension.lower()

        # check if extension is not on blacklist
        if extension not in self.extension_blacklist:

            # try to load extension
            try:
                # load extension
                self.bot.load_extension(self.extensions_dir + extension)

                # check extension in database and update/set
                db_extension = Extension.get(extension)
                if db_extension:
                    db_extension.isLoaded = True
                else:
                    extension_object = Extension(extension, True)
                    db_session.add(extension_object)

                # commit update
                db_session.commit()

            except Exception as e:
                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=_("extension not loaded, {extension}").format(
                        extension=extension))
                embed.add_field(name=_("Errors"),
                                value="{}: {}".format(type(e).__name__, e),
                                inline=False)

                # send embed
                await ctx.send(embed=embed)
            else:
                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.green(),
                    title=_("extension successfully loaded, {extension}"
                            ).format(extension=extension))
                # send embed
                await ctx.send(embed=embed)
        else:
            # create output embed
            embed = discord.Embed(
                colour=discord.Colour.red(),
                title=_("extension not loaded, {extension}").format(
                    extension=extension))
            embed.add_field(name=_("Errors"),
                            value=_("extension blacklist"),
                            inline=False)

            # send embed
            await ctx.send(embed=embed)
Beispiel #4
0
    def __init__(self):
        intents = discord.Intents.default()
        intents.members = True
        intents.presences = True
        super().__init__('!', case_insensitive=True, intents=intents)

        # remove default commands
        self.remove_command('help')

        # try to load extensions management extension
        try:
            self.load_extension('extensions.extensionsmanagement')
        except Exception:
            log.exception(
                "Bot failed to load \"extensionsmanagement\"-extension exception"
            )
            sys.exit()

        # get loaded extension and try to load them
        extensions = Extension.loaded()
        for extension in extensions:
            try:
                self.load_extension('extensions.' + extension.name)
            except Exception:
                extension.isLoaded = False
                db_session.commit()
                log.exception("Bot failed to load the extension \"" +
                              extension.name + "\"")
Beispiel #5
0
    def __init__(self):
        # get config
        self.config = get_config()

        # setup logger if logging is true
        if self.config['bot']['logging'] == 'true':
            # get loggers
            self.discordLogger = logging.getLogger('discord')
            self.sqlalchemyLogger = logging.getLogger('sqlalchemy.engine')

            # set debug levels
            self.discordLogger.setLevel(
                (logging.DEBUG
                 if self.config['bot']['debug'] == 'true' else logging.ERROR))
            self.sqlalchemyLogger.setLevel(
                (logging.DEBUG
                 if self.config['bot']['debug'] == 'true' else logging.ERROR))

            # setup handler
            handler = logging.FileHandler(filename=datetime.now().strftime(
                'logs/log%Y-%m-%d_%H-%M-%S.log'),
                                          encoding='utf-8',
                                          mode='w')
            handler.setFormatter(
                logging.Formatter(
                    '%(asctime)s:%(levelname)s:%(name)s: %(message)s'))

            # add handlers
            self.discordLogger.addHandler(handler)
            self.sqlalchemyLogger.addHandler(handler)

        # setup client
        super().__init__(command_prefix=self.config['bot']['command_prefix'],
                         case_insensitive=True)

        # remove default commands
        self.remove_command('help')

        # try to load extensions management extension
        try:
            self.load_extension('extensions.extensionsmanagement')
        except Exception:
            self.discordLogger.exception(
                "Bot failed to load \"extensions management\" exception")
            sys.exit()

        # get loaded extension and try to load them
        extensions = Extension.loaded()
        for extension in extensions:
            try:
                self.load_extension('extensions.' + extension.name)
            except Exception:
                self.discordLogger.exception(
                    "Bot failed to load the extension \"" + extension.name +
                    "\"")
    async def extensions(self, ctx):

        # create output embeds
        embed_loaded = discord.Embed(colour=discord.Colour.green(),
                                     title="Aktivierte Erweiterungen:")
        embed_unloaded = discord.Embed(colour=discord.Colour.red(),
                                       title="Deaktivierte Erweiterungen:")

        # get loaded extension
        loaded_extensions = Extension.loaded()
        if loaded_extensions:
            for extension in loaded_extensions:
                embed_loaded.add_field(
                    name=extension.name,
                    value=
                    f'Beschreibung: {extension.description} \n Author: {extension.author}',
                    inline=False)
        else:
            embed_loaded.add_field(
                name="Keine Erweiterungen",
                value="Es sind keine Erweiterungen aktiviert!",
                inline=False)

        # get unloaded extension
        unloaded_extensions = Extension.unloaded()
        if unloaded_extensions:
            for extension in unloaded_extensions:
                embed_loaded.add_field(
                    name=extension.name,
                    value=
                    f'Beschreibung: {extension.description} \n Author: {extension.author}',
                    inline=False)
        else:
            embed_unloaded.add_field(
                name="Keine Erweiterungen",
                value="Es sind keine Erweiterungen deaktiviert!",
                inline=False)

        # send embeds
        await ctx.send(ctx.author.mention, embed=embed_loaded)
        await ctx.send(ctx.author.mention, embed=embed_unloaded)
Beispiel #7
0
from models import *
from ext_models.address import Address
from models.extension import Extension
from models.humanname import HumanName
from models.patient import Patient

p = Patient()
p.name = [HumanName()]
p.name[0].use = 'official'
p.name[0].familyname = ['Reenen']
p.name[0].given = ['Hendrikus', 'Herman', 'Johannes']
p.name[0].extension = [Extension()] #niet zeker van juistheid hiervan
p.name[0].extension[0].url = 'http://nictiz.org/huham_name_def_nl/prefix'
p.name[0].extension[0].valueString = 'van'
p.name[0].text = 'Hendrikus Herman Johannes van Reenen'
, 'H', 'H', 'J']
p.active = True
p.address = [Address.from_str("Reigersberg 10, 6865NL, Doorwerth, NL")]

json = p.as_json()
print(json)
import json
s = """{'name': [{'given': ['Pieter', 'H', 'H', 'J']}], 'resourceType': 'Patient'}"""
json_acceptable_string = s.replace("'", "\"")
d = json.loads(json_acceptable_string)

p2 = Patient(d)
json = p2.as_json()
print(json)

p4 = Patient({'resourceType': 'Patient', 'name': [{'given': ['Henk-Jan', 'H', 'H', 'J']}]})