feat: add ban mechanism#211
Conversation
ce3801c to
2534cca
Compare
1bcd442 to
6fb47f1
Compare
| async def test_migration_v6(self): | ||
| await migrations.execute_migrations(self.c, self.dbconn.config, 5) | ||
|
|
||
| with patch('uuid.uuid4') as mock_uuid: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This could be a separate patch
There was a problem hiding this comment.
Created a separate PR, will update this one afterwards
#212
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
I thought that duplicating this function for other notifications channel would be meh, so now there is a common one.
There was a problem hiding this comment.
You can have both _send_notification and _send_user_notification
There was a problem hiding this comment.
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}")) |
There was a problem hiding this comment.
I'm open to a different message
| cli_args=[], | ||
| description='Maximum number of aliases per user', | ||
| default_value=1) | ||
| self.discord_bot_channel_bans_notifications_id = ConfigKey( |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
This could be a separate patch
There was a problem hiding this comment.
Added in #213, not to mention that I still forgot to add it for other bot commands here :/ will update this PR afterwards
6fb47f1 to
8f53475
Compare
| await discord_user.send( | ||
| f"### Ban" | ||
| f"- Your account: `{username}` has been banned." | ||
| f"- Reason: *{reason}*" |
There was a problem hiding this comment.
We could add info:
- who was the one to ban
- smth along the lines of "This does not grant you additional accounts to register"
a430754 to
2118485
Compare
| 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', |
There was a problem hiding this comment.
claiming accounts or claiming an account
| cli_args=[], | ||
| description='Maximum number of aliases per user', | ||
| default_value=1) | ||
| self.discord_bot_channel_bans_notifications_id = ConfigKey( |
| default_value=1) | ||
| self.discord_bot_channel_bans_notifications_id = ConfigKey( | ||
| config=self, | ||
| name='discord.bot.channel_bans_notifications.id', |
| await _set_version(c, 8) | ||
|
|
||
|
|
||
| async def _migration_upgrade_to_v9(c, config): |
There was a problem hiding this comment.
Wouldn't it be better to store bans in a separate table and join?
|
|
||
| @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)) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
You can have both _send_notification and _send_user_notification
| async def test_migration_v6(self): | ||
| await migrations.execute_migrations(self.c, self.dbconn.config, 5) | ||
|
|
||
| with patch('uuid.uuid4') as mock_uuid: |
There was a problem hiding this comment.
This could be a separate patch
|
Can you split this into two PRs: database changes + tests and bot changes? |
946ff37 to
ee5ad01
Compare
ee5ad01 to
8d2981a
Compare
Sure, once I'll get back to this after tournaments |

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