async def regist_message(message: discord.Message):

    lst_command = message.content.split(' ')

    if len(lst_command) != 3:
        raise ValueError('引数の数が違います')

    try:
        if db_access.get_shortcut_message(message.server.id,
                                          lst_command[1].strip()) != None:
            raise ValueError('ショートカット:`{0}`はすでに登録されています'.format(
                lst_command[1].strip()))

        sc_message = await client.get_message(message.channel,
                                              lst_command[2].strip())

        message_list = [
            sc_message.content,
        ] + [file['url'] for file in sc_message.attachments]
        db_access.insert_shortcut(message.server.id, lst_command[1].strip(),
                                  '\n'.join(message_list))

        success_msg = [
            "メッセージを登録しました",
            "ショートカット:`{0}`".format(lst_command[1].strip()),
            "メッセージ:",
            "```",
            '\n'.join(message_list),
            "```",
        ]

        await client.send_message(message.channel, '\n'.join(success_msg))

    except discord.NotFound:
        raise ValueError('メッセージIDが間違っています')
async def delete_message(message: discord.Message):

    lst_command = message.content.split(' ')

    if len(lst_command) != 2:
        raise ValueError('引数の数が違います')

    if db_access.get_shortcut_message(message.server.id,
                                      lst_command[1].strip()) == None:
        raise ValueError('ショートカット:`{0}`は存在しません'.format(lst_command[1].strip()))

    db_access.delete_shortcut(message.server.id, lst_command[1].strip())

    success_msg = 'ショートカット:`{0}` を削除しました'.format(lst_command[1].strip())
    await client.send_message(message.channel, success_msg)
예제 #3
0
async def delete(ctx: commands.context, shortcut: str):
    """
    メッセージショートカット削除
    shortcut: ショートカット名
    """
    try:
        if db_access.get_shortcut_message(ctx.guild.id, shortcut) is None:
            raise ValueError('ショートカット:`{0}`は存在しません'.format(shortcut))

        db_access.delete_shortcut(ctx.guild.id, shortcut)

        success_msg = 'ショートカット:`{0}` を削除しました'.format(shortcut)
        await ctx.send(success_msg)

    except Exception as ex:
        await ctx.send(ex)
예제 #4
0
async def get_message(message: discord.Message):
    if message.author.bot:
        return

    elif message.content.startswith(PREFIX):
        return

    try:
        msg = db_access.get_shortcut_message(message.guild.id, message.content)

        if msg is None:
            return

        await message.channel.send(msg)

    except Exception as ex:
        await message.channel.send(ex)
예제 #5
0
async def add(ctx: commands.context, shortcut: str, message_id: int):
    """
    メッセージショートカット登録
    shortcut: ショートカット名
    message_id: メッセージID
    """
    try:
        try:
            if db_access.get_shortcut_message(ctx.guild.id,
                                              shortcut) is not None:
                raise ValueError('ショートカット:`{0}`はすでに登録されています'.format(shortcut))

            sc_message = await ctx.fetch_message(message_id)

            if sc_message.content.startswith(PREFIX):
                raise ValueError('{0}から始まるメッセージは登録できません'.format(PREFIX))

            message_list = [
                sc_message.content,
            ] + [file['url'] for file in sc_message.attachments]
            db_access.insert_shortcut(ctx.guild.id, shortcut,
                                      '\n'.join(message_list))

            success_msg = [
                "メッセージを登録しました",
                "ショートカット:`{0}`".format(shortcut.strip()),
                "メッセージ:",
                "```",
                '\n'.join(message_list),
                "```",
            ]

            await ctx.send('\n'.join(success_msg))

        except discord.NotFound as ex:
            raise ValueError('メッセージIDが間違っています')

    except Exception as ex:
        await ctx.send(ex)
async def get_message(message: discord.Message):

    print(message.attachments)
    lst_command = message.content.split(' ')

    msg = db_access.get_shortcut_message(message.server.id, lst_command[0])

    if msg != None:
        if len(lst_command) == 1 and message.content == lst_command[0]:
            await client.send_message(message.channel, msg)

        elif len(lst_command) == 2:
            try:
                user_id = lst_command[1]

                for c in ('<@', '>', '!'):
                    user_id = user_id.replace(c, '')

                send_user = await client.get_user_info(user_id)
                await client.send_message(send_user, msg)

            except:
                pass