Exemplo n.º 1
0
async def rooms_add(ctx: commands.Context, channel_id: int) -> None:
    """Declares a discord channel as a standup room."""

    conflicting_room = Room.select().where(Room.channel_id == channel_id).first()
    if conflicting_room:
        await ctx.send(f"```Failed: channel '{channel_id}' already is a room.```")
        raise commands.CommandError()

    Room.create(channel_id=channel_id)
    def test_update_roles(self) -> None:
        room = Room.create(channel_id=0, cooldown=10)
        room.update_roles({1, 2, 3})

        result = set(r.role_id
                     for r in RoomRole.select().where(RoomRole.room == room))
        assert result == {1, 2, 3}
Exemplo n.º 3
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)
    def test_format_for_listing_lists_roles(self) -> None:
        room = Room.create(channel_id=0, cooldown=10)
        RoomRole.bulk_create([
            RoomRole(room=room, role_id=12312321),
            RoomRole(room=room, role_id=123812)
        ])

        assert (room.format_for_listing() ==
                "0 | Cooldown: 10 | Roles: {12312321, 123812}")
Exemplo n.º 5
0
async def rooms_list(ctx: commands.Context) -> None:
    """Lists all created standup rooms along with their assigned roles."""

    rooms = Room.select()
    formatted = (r.format_for_listing() for r in rooms)
    numbered = (f"{i}: {string}" for i, string in enumerate(formatted, 1))
    joined = "\n".join(numbered)

    await ctx.send(f"```\n{joined}```")
    def test_create(self) -> None:
        date = datetime(1970, 1, 1)
        room = Room.create(channel_id=0)
        Post.create(
            room=room,
            user_id=0,
            timestamp=date.replace(tzinfo=timezone.utc),
            message_id=0,
        )

        assert [p.timestamp for p in Post.select()] == [date]
Exemplo n.º 7
0
async def rooms_config(ctx: commands.Context, room: int, key: str, value: str) -> None:
    """
    Configures a standup room's key-value properties.

    Keys:
    - 'roles': Accepts a comma separated list of role IDs. Use empty quotes to
      specify an empty list.
    - 'cooldown': Accepts an integer value representing seconds. (default: 3600)
    """

    target_room = Room.select().where(Room.channel_id == room).first()
    if not target_room:
        ctx.send(f"```\nFailed: room '{room}' does not exist.```")
        raise commands.CommandError()

    if key == "roles":
        snowflakes = _parse_snowflake_csv(value)
        target_room.update_roles(snowflakes)
    elif key == "cooldown":
        Room.update(cooldown=int(value)).where(Room.channel_id == room).execute()
    def test_is_expired(self) -> None:
        date = datetime(1970, 1, 1, tzinfo=timezone.utc)
        room = Room.create(channel_id=0, cooldown=10)
        Post.create(room=room, user_id=0, timestamp=date, message_id=0)
        Post.create(room=room,
                    user_id=0,
                    timestamp=(date + timedelta(seconds=20)),
                    message_id=0)

        target_time = datetime(1970, 1, 1,
                               tzinfo=timezone.utc) + timedelta(seconds=11)
        result = Post.select().join(Room).where(Post.is_expired(target_time))
        assert len(result) == 1
 def test_format_for_listing(self) -> None:
     room = Room.create(channel_id=0, cooldown=10)
     assert room.format_for_listing() == "0 | Cooldown: 10 | Roles: {}"
Exemplo n.º 10
0
async def rooms_remove(_, channel_id: int) -> None:
    """Removes a discord channel from the list of functional standup rooms."""

    Room.delete().where(Room.channel_id == channel_id).execute()