tux.database.controllers.note
¶
Classes:
Name | Description |
---|---|
NoteController | Controller for managing moderator notes. |
Classes¶
NoteController()
¶
Bases: BaseController[Note]
Controller for managing moderator notes.
This controller provides methods for creating, retrieving, updating, and deleting moderator notes for users in guilds.
Initialize the NoteController with the note table.
Methods:
Name | Description |
---|---|
get_all_notes | Get all notes across all guilds. |
get_note_by_id | Get a note by its ID. |
insert_note | Create a new moderator note. |
find_one | Return the first row that matches where or None. |
delete_note_by_id | Delete a note by its ID. |
update_note_by_id | Update a note's content. |
find_many | Return a list of rows matching where (or all rows). |
get_notes_by_user_id | Get all notes for a user across all guilds. |
get_notes_by_moderator_id | Get all notes created by a moderator across all guilds. |
get_notes_by_guild_id | Get all notes for a guild. |
get_notes_by_user_id_and_guild_id | Get all notes for a user in a specific guild. |
get_notes_by_moderator_id_and_guild_id | Get all notes created by a moderator in a specific guild. |
get_notes_by_user_id_and_moderator_id | Get all notes for a user created by a specific moderator. |
execute_transaction | Execute callback inside a database session / transaction block. |
safe_get_attr | Return |
get_notes_by_user_id_moderator_id_and_guild_id | Get all notes for a user created by a specific moderator in a specific guild. |
connect_or_create_relation | Return a dict with a single key that can be merged into data dicts. |
count_notes_by_guild_id | Count the number of notes in a guild. |
count_notes_by_user_id | Count the number of notes for a user. |
bulk_delete_notes_by_guild_id | Delete all notes for a guild. |
Source code in tux/database/controllers/note.py
Functions¶
get_all_notes() -> list[Note]
async
¶
get_note_by_id(note_id: int) -> Note | None
async
¶
Get a note by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_id | int | The ID of the note to get | required |
Returns:
Type | Description |
---|---|
Note | None | The note if found, None otherwise |
Source code in tux/database/controllers/note.py
insert_note(note_user_id: int, note_moderator_id: int, note_content: str, guild_id: int) -> Note
async
¶
Create a new moderator note.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_user_id | int | The ID of the user the note is about | required |
note_moderator_id | int | The ID of the moderator creating the note | required |
note_content | str | The content of the note | required |
guild_id | int | The ID of the guild the note belongs to | required |
Returns:
Type | Description |
---|---|
Note | The created note |
Source code in tux/database/controllers/note.py
async def insert_note(
self,
note_user_id: int,
note_moderator_id: int,
note_content: str,
guild_id: int,
) -> Note:
"""Create a new moderator note.
Parameters
----------
note_user_id : int
The ID of the user the note is about
note_moderator_id : int
The ID of the moderator creating the note
note_content : str
The content of the note
guild_id : int
The ID of the guild the note belongs to
Returns
-------
Note
The created note
"""
return await self.create(
data={
"note_user_id": note_user_id,
"note_moderator_id": note_moderator_id,
"note_content": note_content,
"guild": self.connect_or_create_relation("guild_id", guild_id),
},
include={"guild": True},
)
_execute_query(op: Callable[[AsyncSession], Any], span_desc: str) -> Any
async
¶
Run op inside a managed session & sentry span (if enabled).
Source code in tux/database/controllers/note.py
async def insert_note(
self,
note_user_id: int,
note_moderator_id: int,
note_content: str,
guild_id: int,
) -> Note:
"""Create a new moderator note.
Parameters
----------
note_user_id : int
The ID of the user the note is about
note_moderator_id : int
The ID of the moderator creating the note
note_content : str
The content of the note
guild_id : int
The ID of the guild the note belongs to
find_one(*, where: dict[str, Any], include: dict[str, bool] | None = None, **__: Any) -> ModelT | None
async
¶
Return the first row that matches where or None.
Source code in tux/database/controllers/note.py
"""
return await self.create(
data={
"note_user_id": note_user_id,
"note_moderator_id": note_moderator_id,
"note_content": note_content,
"guild": self.connect_or_create_relation("guild_id", guild_id),
},
include={"guild": True},
)
async def delete_note_by_id(self, note_id: int) -> Note | None:
"""Delete a note by its ID.
Parameters
delete_note_by_id(note_id: int) -> Note | None
async
¶
Delete a note by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_id | int | The ID of the note to delete | required |
Returns:
Type | Description |
---|---|
Note | None | The deleted note if found, None otherwise |
Source code in tux/database/controllers/note.py
update_note_by_id(note_id: int, note_content: str) -> Note | None
async
¶
Update a note's content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_id | int | The ID of the note to update | required |
note_content | str | The new content for the note | required |
Returns:
Type | Description |
---|---|
Note | None | The updated note if found, None otherwise |
Source code in tux/database/controllers/note.py
async def update_note_by_id(self, note_id: int, note_content: str) -> Note | None:
"""Update a note's content.
Parameters
----------
note_id : int
The ID of the note to update
note_content : str
The new content for the note
Returns
-------
Note | None
The updated note if found, None otherwise
"""
return await self.update(
where={"note_id": note_id},
data={"note_content": note_content},
)
find_many(*, where: dict[str, Any] | None = None, include: dict[str, bool] | None = None, order: dict[str, str] | None = None, take: int | None = None, skip: int | None = None) -> list[ModelT]
async
¶
Return a list of rows matching where (or all rows).
Source code in tux/database/controllers/note.py
Parameters
----------
note_id : int
The ID of the note to update
note_content : str
The new content for the note
Returns
-------
Note | None
The updated note if found, None otherwise
"""
return await self.update(
where={"note_id": note_id},
data={"note_content": note_content},
)
async def get_notes_by_user_id(self, note_user_id: int, limit: int | None = None) -> list[Note]:
"""Get all notes for a user across all guilds.
Parameters
----------
note_user_id : int
The ID of the user to get notes for
limit : int | None
Optional limit on the number of notes to return
get_notes_by_user_id(note_user_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes for a user across all guilds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_user_id | int | The ID of the user to get notes for | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes for the user |
Source code in tux/database/controllers/note.py
async def get_notes_by_user_id(self, note_user_id: int, limit: int | None = None) -> list[Note]:
"""Get all notes for a user across all guilds.
Parameters
----------
note_user_id : int
The ID of the user to get notes for
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes for the user
"""
return await self.find_many(where={"note_user_id": note_user_id}, take=limit)
get_notes_by_moderator_id(moderator_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes created by a moderator across all guilds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
moderator_id | int | The ID of the moderator to get notes for | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes created by the moderator |
Source code in tux/database/controllers/note.py
async def get_notes_by_moderator_id(self, moderator_id: int, limit: int | None = None) -> list[Note]:
"""Get all notes created by a moderator across all guilds.
Parameters
----------
moderator_id : int
The ID of the moderator to get notes for
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes created by the moderator
"""
return await self.find_many(where={"note_moderator_id": moderator_id}, take=limit)
get_notes_by_guild_id(guild_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes for a guild.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
guild_id | int | The ID of the guild to get notes for | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes for the guild |
Source code in tux/database/controllers/note.py
async def get_notes_by_guild_id(self, guild_id: int, limit: int | None = None) -> list[Note]:
"""Get all notes for a guild.
Parameters
----------
guild_id : int
The ID of the guild to get notes for
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes for the guild
"""
return await self.find_many(where={"guild_id": guild_id}, take=limit)
get_notes_by_user_id_and_guild_id(note_user_id: int, guild_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes for a user in a specific guild.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
note_user_id | int | The ID of the user to get notes for | required |
guild_id | int | The ID of the guild to get notes from | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes for the user in the guild |
Source code in tux/database/controllers/note.py
async def get_notes_by_user_id_and_guild_id(
self,
note_user_id: int,
guild_id: int,
limit: int | None = None,
) -> list[Note]:
"""Get all notes for a user in a specific guild.
Parameters
----------
note_user_id : int
The ID of the user to get notes for
guild_id : int
The ID of the guild to get notes from
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes for the user in the guild
"""
return await self.find_many(where={"note_user_id": note_user_id, "guild_id": guild_id}, take=limit)
get_notes_by_moderator_id_and_guild_id(moderator_id: int, guild_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes created by a moderator in a specific guild.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
moderator_id | int | The ID of the moderator to get notes for | required |
guild_id | int | The ID of the guild to get notes from | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes created by the moderator in the guild |
Source code in tux/database/controllers/note.py
async def get_notes_by_moderator_id_and_guild_id(
self,
moderator_id: int,
guild_id: int,
limit: int | None = None,
) -> list[Note]:
"""Get all notes created by a moderator in a specific guild.
Parameters
----------
moderator_id : int
The ID of the moderator to get notes for
guild_id : int
The ID of the guild to get notes from
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes created by the moderator in the guild
"""
return await self.find_many(where={"note_moderator_id": moderator_id, "guild_id": guild_id}, take=limit)
get_notes_by_user_id_and_moderator_id(user_id: int, moderator_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes for a user created by a specific moderator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id | int | The ID of the user to get notes for | required |
moderator_id | int | The ID of the moderator who created the notes | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes for the user created by the moderator |
Source code in tux/database/controllers/note.py
async def get_notes_by_user_id_and_moderator_id(
self,
user_id: int,
moderator_id: int,
limit: int | None = None,
) -> list[Note]:
"""Get all notes for a user created by a specific moderator.
Parameters
----------
user_id : int
The ID of the user to get notes for
moderator_id : int
The ID of the moderator who created the notes
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes for the user created by the moderator
"""
return await self.find_many(where={"note_user_id": user_id, "note_moderator_id": moderator_id}, take=limit)
execute_transaction(callback: Callable[[], Any]) -> Any
async
¶
Execute callback inside a database session / transaction block.
Source code in tux/database/controllers/note.py
safe_get_attr(obj: Any, attr: str, default: Any = None) -> Any
staticmethod
¶
get_notes_by_user_id_moderator_id_and_guild_id(user_id: int, moderator_id: int, guild_id: int, limit: int | None = None) -> list[Note]
async
¶
Get all notes for a user created by a specific moderator in a specific guild.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id | int | The ID of the user to get notes for | required |
moderator_id | int | The ID of the moderator who created the notes | required |
guild_id | int | The ID of the guild to get notes from | required |
limit | int | None | Optional limit on the number of notes to return | None |
Returns:
Type | Description |
---|---|
list[Note] | List of notes for the user created by the moderator in the guild |
Source code in tux/database/controllers/note.py
async def get_notes_by_user_id_moderator_id_and_guild_id(
self,
user_id: int,
moderator_id: int,
guild_id: int,
limit: int | None = None,
) -> list[Note]:
"""Get all notes for a user created by a specific moderator in a specific guild.
Parameters
----------
user_id : int
The ID of the user to get notes for
moderator_id : int
The ID of the moderator who created the notes
guild_id : int
The ID of the guild to get notes from
limit : int | None
Optional limit on the number of notes to return
Returns
-------
list[Note]
List of notes for the user created by the moderator in the guild
"""
return await self.find_many(
where={
"note_user_id": user_id,
"note_moderator_id": moderator_id,
"guild_id": guild_id,
},
take=limit,
)
connect_or_create_relation(id_field: str, model_id: Any, *_: Any, **__: Any) -> dict[str, Any]
staticmethod
¶
Return a dict with a single key that can be merged into data dicts.
The calling code does something like::
data = {"guild": connect_or_create_relation("guild_id", guild_id)}
We map that pattern to a very small helper that collapses to {"guild_id": guild_id}
.
Source code in tux/database/controllers/note.py
count_notes_by_guild_id(guild_id: int) -> int
async
¶
count_notes_by_user_id(user_id: int, guild_id: int | None = None) -> int
async
¶
Count the number of notes for a user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id | int | The ID of the user to count notes for | required |
guild_id | int | None | Optional guild ID to restrict the count to | None |
Returns:
Type | Description |
---|---|
int | The number of notes for the user |
Source code in tux/database/controllers/note.py
async def count_notes_by_user_id(self, user_id: int, guild_id: int | None = None) -> int:
"""Count the number of notes for a user.
Parameters
----------
user_id : int
The ID of the user to count notes for
guild_id : int | None
Optional guild ID to restrict the count to
Returns
-------
int
The number of notes for the user
"""
where = {"note_user_id": user_id}
if guild_id is not None:
where["guild_id"] = guild_id
return await self.count(where=where)