示例#1
0
async def on_message(msg: discord.Message) -> None:
    await BOT.process_commands(msg)

    messaged_room = Room.select().where(Room.channel_id == msg.channel.id).first()
    if not messaged_room:
        return

    if not message_is_formatted(msg.content):
        await msg.delete()

        dm_help = (
            "Your posted standup is incorrectly formatted:\n"
            f"```{msg.content}```"
            "Please format your standup correctly, here is a template example: ```\n"
            "**Yesterday I:** [...]\n"
            "**Today I will:** [...]\n"
            "**Potential hard problems:** [...]\n"
            "```"
        )

        if msg.type is not MessageType.pins_add:
            await msg.author.send(dm_help)
        return

    new_post = Post.create(
        room=messaged_room,
        user_id=msg.author.id,
        timestamp=datetime.now(tz=timezone.utc),
        message_id=msg.id,
    )

    await _post_setup_roles(new_post)
示例#2
0
def test_message_is_formatted_accepts_plain() -> None:
    msg = (
        "**Yesterday I:** Did nothing!\n"
        "**Today I will:** Work on my discord bot!\n"
        "**Potential hard problems:** None!"
    )

    assert message_is_formatted(msg)
示例#3
0
def test_message_is_formatted_fails_improper_newlines() -> None:
    msg = (
        "**Yesterday I:** did nothing!"
        "**Today I will:** Work on my discord bot!"
        "**Potential hard problems:** None!"
    )

    assert not message_is_formatted(msg)