Skip to content

feat: add ban mechanism#211

Open
Fruktus wants to merge 1 commit into
masterfrom
feat/bot-bans
Open

feat: add ban mechanism#211
Fruktus wants to merge 1 commit into
masterfrom
feat/bot-bans

Conversation

@Fruktus
Copy link
Copy Markdown
Owner

@Fruktus Fruktus commented Nov 17, 2025

adds mechanism which will allow us to ban/unban users (in-game)

@Fruktus
Copy link
Copy Markdown
Owner Author

Fruktus commented Nov 17, 2025

image

@Fruktus Fruktus force-pushed the feat/bot-bans branch 4 times, most recently from 1bcd442 to 6fb47f1 Compare November 17, 2025 20:58
Comment thread server/tests/test_db.py
async def test_migration_v6(self):
await migrations.execute_migrations(self.c, self.dbconn.config, 5)

with patch('uuid.uuid4') as mock_uuid:
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TLDR: Migration tests should not cover anything else than migrations, no other connector-related functions, since these are not versioned in the same way as migrations.

These tests had to go, since they rely on other functions, which have no concept of migration and do not work now (since at v6 there is no is_banned column) - this would be a problem with any other modification to users table.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a separate patch

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a separate PR, will update this one afterwards
#212

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folloup: the general idea was to remove the test which did not fit. The test did not fit, since it relied on connector's functions, which were updated without any relation to migrations, which caused it to fail here. The initial idea was to delete the test, since it tested the stuff outside of migration, but during the analysis, KJ noticed that the test was, actually, not misplaced, since it tested the migration from one set of data (matches) to two (matches and ranking scores). therefore, to make it work, we will replace the connector-related functions (which are subject to change) with raw sql queries

async def _send_user_notification(self, message: str) -> None:
# Send a message to the user notifications channel
if not self.user_notifications_channel_id:
async def _send_notification(self, message: str, channel: str) -> None:
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that duplicating this function for other notifications channel would be meh, so now there is a common one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have both _send_notification and _send_user_notification

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could but I don't think it's a good idea, especially since the only difference is the target channel


if db_user.is_banned:
await self.send_msg(LobbyStateResponse.new([]))
await self.send_msg(LobbyChatMessage.new(None, f"You have been banned. Reason: {db_user.ban_reason}"))
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to a different message

Comment thread server/src/QRServer/config.py Outdated
cli_args=[],
description='Maximum number of aliases per user',
default_value=1)
self.discord_bot_channel_bans_notifications_id = ConfigKey(
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the description should indicate that ban channel and user notifications channel can be the same one


@self.tree.command(name="resetpassword", description="Reset password for a member")
@self.tree.command(name="resetpassword", description="Reset password for a member",
guild=discord.Object(id=self.guild_id))
Copy link
Copy Markdown
Owner Author

@Fruktus Fruktus Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing guild ids are mistake from before, which no-one spotted - without these, the commands are added globally. We (me) probably added all of these during initial testing and did not notice later on. If this param is not present, the tree commands won't be synced to a given server

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a separate patch

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #213, not to mention that I still forgot to add it for other bot commands here :/ will update this PR afterwards

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#213 merged, will rebase this

Comment thread server/src/QRServer/discord/bot.py Outdated
await discord_user.send(
f"### Ban"
f"- Your account: `{username}` has been banned."
f"- Reason: *{reason}*"
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add info:

  • who was the one to ban
  • smth along the lines of "This does not grant you additional accounts to register"

@Fruktus Fruktus force-pushed the feat/bot-bans branch 4 times, most recently from a430754 to 2118485 Compare November 21, 2025 18:13
name='discord.bot.channel_user_notifications.id',
cli_args=[],
description='Discord Channel ID for user notifications such as registration, claiming of account or bans',
description='Discord Channel ID for user notifications such as registration or claiming of account',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claiming accounts or claiming an account

Comment thread server/src/QRServer/config.py Outdated
cli_args=[],
description='Maximum number of aliases per user',
default_value=1)
self.discord_bot_channel_bans_notifications_id = ConfigKey(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ban_notifications

Comment thread server/src/QRServer/config.py Outdated
default_value=1)
self.discord_bot_channel_bans_notifications_id = ConfigKey(
config=self,
name='discord.bot.channel_bans_notifications.id',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ban_notifications

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

await _set_version(c, 8)


async def _migration_upgrade_to_v9(c, config):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to store bans in a separate table and join?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, can do, will do


@self.tree.command(name="resetpassword", description="Reset password for a member")
@self.tree.command(name="resetpassword", description="Reset password for a member",
guild=discord.Object(id=self.guild_id))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a separate patch

async def _send_user_notification(self, message: str) -> None:
# Send a message to the user notifications channel
if not self.user_notifications_channel_id:
async def _send_notification(self, message: str, channel: str) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have both _send_notification and _send_user_notification

Comment thread server/tests/test_db.py
async def test_migration_v6(self):
await migrations.execute_migrations(self.c, self.dbconn.config, 5)

with patch('uuid.uuid4') as mock_uuid:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a separate patch

@kjarosh
Copy link
Copy Markdown
Collaborator

kjarosh commented Nov 22, 2025

Can you split this into two PRs: database changes + tests and bot changes?

@Fruktus Fruktus force-pushed the feat/bot-bans branch 2 times, most recently from 946ff37 to ee5ad01 Compare November 23, 2025 17:17
@Fruktus
Copy link
Copy Markdown
Owner Author

Fruktus commented Nov 27, 2025

Can you split this into two PRs: database changes + tests and bot changes?

Sure, once I'll get back to this after tournaments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants