Пример #1
0
async def on_server_unavailable(server):
    event = Map({})
    event.server = server

    await loader.execute(command=None,
                         cmdtype="ServerDisable",
                         event=event,
                         client=client)
Пример #2
0
async def on_server_join(server):
    event = Map({})
    event.server = server

    await loader.execute(command=None,
                         cmdtype="BotJoin",
                         event=event,
                         client=client)
Пример #3
0
async def on_server_update(post, pre):
    event = Map({})
    event.old = post
    event.new = pre

    await loader.execute(command=None,
                         cmdtype="ServerChange",
                         event=event,
                         client=client)
Пример #4
0
async def on_member_join(member):

    event = Map({})
    event.member = member

    await loader.execute(command=None,
                         cmdtype="MemberJoin",
                         event=event,
                         client=client)
Пример #5
0
async def on_server_role_delete(role):
    event = Map({})
    event.role = role
    event.server = role.server

    await loader.execute(command=None,
                         cmdtype="RoleRemove",
                         event=event,
                         client=client)
Пример #6
0
async def on_member_unban(member):

    event = Map({})
    event.member = member
    event.server = member.server

    await loader.execute(command=None,
                         cmdtype="MemberUnban",
                         event=event,
                         client=client)
Пример #7
0
async def on_voice_state_update(pre, post):
    event = Map({})
    event.old = pre
    event.new = post
    event.server = pre.server

    await loader.execute(command=None,
                         cmdtype="RoleRemove",
                         event=event,
                         client=client)
Пример #8
0
async def on_member_remove(member):

    event = Map({})
    event.member = member
    event.server = member.server

    await loader.execute(command=None,
                         cmdtype="MemberLeave",
                         event=event,
                         client=client)
Пример #9
0
async def on_channel_delete(channel):

    event = Map({})
    event.channel = channel
    event.server = channel.server

    await loader.execute(command=None,
                         cmdtype="ChannelRemove",
                         event=event,
                         client=client)
Пример #10
0
async def on_reaction_clear(reactions, message):

    event = Map({})
    event.reactions = reactions
    event.message = message
    event.server = message.server

    await loader.execute(command=None,
                         cmdtype="ReactClear",
                         event=event,
                         client=client)
Пример #11
0
async def on_member_update(pre, post):

    event = Map({})
    event.old = pre
    event.new = post
    event.server = pre.server

    await loader.execute(command=None,
                         cmdtype="MemberUpdate",
                         event=event,
                         client=client)
Пример #12
0
async def on_reaction_remove(reaction, user):

    event = Map({})
    event.reaction = reaction
    event.user = user
    event.server = user.server

    await loader.execute(command=None,
                         cmdtype="ReactRemove",
                         event=event,
                         client=client)
Пример #13
0
async def on_message_delete(message):

    event = Map({})
    event.message = message
    event.user = message.author
    event.server = message.server

    await loader.execute(command=None,
                         cmdtype="Delete",
                         event=event,
                         client=client)
Пример #14
0
async def on_typing(channel, user, when):
    event = Map({})
    event.channel = channel
    event.user = user
    event.when = when
    event.arrow = arrow.get(str(when), "YYYY-MM-DD HH:mm:ss")
    event.timestamp = event.arrow.timestamp

    await loader.execute(command=None,
                         cmdtype="Typing",
                         event=event,
                         client=client)
Пример #15
0
async def on_server_emojis_update(post, pre):
    event = Map({})
    event.old = post
    event.new = pre
    event.server = post[0].server

    if len(old) < len(new):
        event.create = True
        # Sets emoji variable to the changed emoji
        event.emoji = [emoji for emoji in pre if emoji not in post][0]

    if len(old) > len(new):
        event.create = False
        # Sets emoji variable to the changed emoji
        event.emoji = [emoji for emoji in post if emoji not in pre][0]

    await loader.execute(command=None,
                         cmdtype="EmojiUpdate",
                         event=event,
                         client=client)
Пример #16
0
    async def execute(self, **options):
        options = Map(options)

        for mod in self.modules:
            commands = getattr(mod.loader, options.cmdtype)

            if options.command is None:
                for func in list(commands.values()):
                    try:
                        print("[cmd:{0}] ?> {1}".format(
                            options.cmdtype, func.__name__))
                        await func(options.event, options.client)
                    except:
                        print(traceback.print_exc())
                return

            print("[cmd:{0}] ?> {1}".format(options.cmdtype, options.command))

            if options.command in commands:
                print("[cmd:{0}] OK> {1}".format(options.cmdtype,
                                                 options.event.args))
                user_roles = [x.name for x in options.event.user.roles]
                print("user_roles: {0}".format(user_roles))

                try:
                    await commands[options.command](options.event,
                                                    options.client)
                except:

                    try:
                        print("[cmd:{0}] !".format(options.cmdtype))
                        em = embed.err_invalid(
                            mod.loader._help[options.command], options.client)
                        print(em)
                        await options.client.send_message(
                            options.event.message.channel, embed=em)
                    except:

                        print("[cmd:{0}] !!".format(options.cmdtype))
                        em = embed.err_invalid("Generic command Error!",
                                               options.client)
                        print(em)
                        await options.client.send_message(
                            options.event.message.channel, embed=em)
Пример #17
0
    async def execute(self, **options):
        #print(f"Event: {options['']}")
        options = Map(options)
        options.client.embeds = embed.EmbedEngine(options.client)
        options.client.config = lambda x: SM.SessionManager(f"botdata\\{x}")

        for module in self.modules:
            for event in module.Events:
                #print(event["type"])
                fl_res = await self.filter(event, options)
                if not fl_res:
                    continue

                print(f"Check Success, Executing Command.")
                if options.event:
                    if "channel" in options.event:
                        print(
                            f"Source: #{options.event.channel.name}({options.event.channel.id})"
                        )
                pprint(event)

                try:
                    print(Style.RESET_ALL, end="\r")
                    await event["function"](options.event, options.client)
                    print(Style.BRIGHT, end="\r")
                except:
                    traceback.print_exc()
                    if event["help"]:
                        print("{}[cmd:{}] !".format(Fore.RED, options.cmdtype))
                        em = embed.err_invalid(event["help"], options.client)
                        await options.event.message.channel.send(embed=em)
                    elif event["error"]:
                        print("{}[cmd:{}] !!".format(Fore.RED,
                                                     options.cmdtype))
                        em = embed.err_invalid("Command Error!",
                                               options.client)
                        await options.event.message.channel.send(embed=em)

        print(Style.RESET_ALL, end="\r")
Пример #18
0
async def on_message_edit(pre, post):

    event = Map({})
    event.old = pre
    event.new = post
    event.message = post
    event.user = pre.author
    event.server = pre.server

    await loader.execute(command=None,
                         cmdtype="Edit",
                         event=event,
                         client=client)

    if not post.content.startswith(settings.PREFIX):
        return

    event.args = post.content[len(settings.PREFIX):].split(" ")
    command = post.content.split(" ")[0][len(settings.PREFIX):]
    # Execute any specific commands
    await loader.execute(command=command,
                         cmdtype="Command",
                         event=event,
                         client=client)
Пример #19
0
async def on_message(message):

    event = Map({})
    event.message = message
    event.server = message.server
    event.user = message.author

    # Execute all of the on_message commands first
    await loader.execute(command=None,
                         cmdtype="Message",
                         event=event,
                         client=client)

    # Checks if it actually is a command
    if not message.content.startswith(settings.PREFIX):
        return

    event.args = message.content[len(settings.PREFIX):].split(" ")
    command = message.content.split(" ")[0][len(settings.PREFIX):]
    # Execute any specific commands
    await loader.execute(command=command,
                         cmdtype="Command",
                         event=event,
                         client=client)
Пример #20
0
    async def execute(self, **options):
        options = Map(options)
        options.client.loader = self

        for mod in self.modules:
            # How is this appending
            # I have no idea
            # What was I drinking?!
            commands = getattr(mod.on, options.cmdtype)

        print(Style.BRIGHT, end="\r")

        if options.command is None:
            for func in list(commands.values()):
                try:
                    print(Style.BRIGHT, end="\r")
                    print("{}[cmd:{}] ?> {}".format(Fore.GREEN,
                                                    options.cmdtype,
                                                    func.__name__))
                    print(Style.RESET_ALL, end="\r")
                    await func(options.event, options.client)
                    print(Style.BRIGHT, end="\r")
                except:
                    print(traceback.print_exc())
            return

        print("{}[cmd:{}] ?> {}".format(Fore.YELLOW, options.cmdtype,
                                        options.command))

        if options.command in commands:
            print("{}[cmd:{}] OK> {}".format(Fore.GREEN, options.cmdtype,
                                             options.event.args))
            #try:
            max_pow = 1
            req_pow = mod.on._role[options.command]
            print(req_pow)
            if req_pow != 1:
                for role in [x.name for x in options.event.user.roles]:
                    for x in settings.ROLE:
                        if role in settings.ROLE[x] and max_pow < x:
                            max_pow = x
                print(max_pow)
                if req_pow > max_pow:
                    em = embed.failed(
                        "You don't have enough permissions for that.",
                        options.client)
                    msg = await options.event.message.channel.send(embed=em)
                    await asyncio.sleep(10)
                    await msg.delete()
                    return

                # print("user_roles: {0}".format(ascii(user_roles)))
            #except:
            #    pass

            try:
                print(Style.RESET_ALL, end="\r")
                await commands[options.command](options.event, options.client)
                print(Style.BRIGHT, end="\r")
            except:

                try:
                    traceback.print_exc()
                    if commands[options.command].__doc__ is not None:
                        print("{}[cmd:{}] !".format(Fore.RED, options.cmdtype))
                        em = embed.err_invalid(
                            commands[options.command].__doc__, options.client)
                    else:
                        print("{}[cmd:{}] !".format(Fore.RED, options.cmdtype))
                        em = embed.err_invalid(mod.on._help[options.command],
                                               options.client)
                    await options.event.message.channel.send(embed=em)
                except:
                    traceback.print_exc()
                    print("{}[cmd:{}] !!".format(Fore.RED, options.cmdtype))
                    em = embed.err_invalid("Generic command Error!",
                                           options.client)
                    await options.event.message.channel.send(embed=em)

        print(Style.RESET_ALL, end="\r")