Services¶
The service layer lives in website/services/ and contains all business logic. Services are the primary place for new logic in QuestMaster.
Services:
- Own transaction boundaries
- Perform validation and enforce business rules
- Raise domain-specific exceptions from
website.exceptions - Call repositories for data access
- Never access Flask
requestorsessiondirectly
Overview¶
| Service | Repository | Model | Description |
|---|---|---|---|
ChannelService |
ChannelRepository |
Channel |
Category size management and Discord channel cleanup |
DiscordService |
Discord (client) |
— | Discord API wrapper with dependency injection for testability |
GameService |
GameRepository |
Game |
Complete game lifecycle — creation, publishing, registration, archival, Discord sync |
GameEventService |
GameEventRepository |
GameEvent |
Transaction-safe audit trail logging for games |
GameSessionService |
GameSessionRepository |
GameSession |
Session CRUD with conflict detection and validation |
SpecialEventService |
SpecialEventRepository |
SpecialEvent |
Special event CRUD with uniqueness validation |
SystemService |
SystemRepository |
System |
Game system CRUD with cache invalidation |
TrophyService |
TrophyRepository |
Trophy |
Trophy awarding logic (unique vs. non-unique rules) and leaderboards |
UserService |
UserRepository |
User |
User retrieval, creation, and Discord profile initialization |
VttService |
VttRepository |
Vtt |
Virtual tabletop CRUD with cache invalidation |
API Reference¶
Service layer for business logic and transaction management.
ChannelService
¶
Service layer for Channel (Discord category) management.
Handles category size tracking for Discord channel organization.
Source code in website/services/channel.py
get_category(game_type)
¶
Get the smallest category for a game type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game_type
|
str
|
Type of game (oneshot, campaign). |
required |
Returns:
| Type | Description |
|---|---|
Channel
|
Channel category with smallest size. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If no category found for type. |
Source code in website/services/channel.py
increment_size(channel)
¶
Increment the channel count for a category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Channel
|
Channel category to increment. |
required |
adjust_category_size(discord_service, game)
¶
Decrement category size when a game channel is deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
discord_service
|
DiscordService
|
DiscordService instance for API calls. |
required |
game
|
Game
|
Game instance with channel to look up. |
required |
Source code in website/services/channel.py
DiscordService
¶
Service layer for Discord API interactions.
Provides a testable wrapper around the Discord API client. Uses dependency injection to allow mocking in tests.
Attributes:
| Name | Type | Description |
|---|---|---|
bot |
Discord
|
The underlying Discord API client instance. |
Source code in website/services/discord.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
bot
property
¶
Get the Discord bot instance.
Lazy-loads from the global singleton if not injected.
Returns:
| Type | Description |
|---|---|
Discord
|
Discord client instance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no bot instance is available. |
get_user(user_id)
¶
Fetch guild member data from Discord.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Member data dictionary from Discord API. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
add_role_to_user(user_id, role_id)
¶
Add a role to a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
role_id
|
str
|
Discord role ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
API response (usually empty on success). |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
remove_role_from_user(user_id, role_id)
¶
Remove a role from a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
role_id
|
str
|
Discord role ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
API response (usually empty on success). |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
create_role(name, permissions=PLAYER_ROLE_PERMISSION, color=0)
¶
Create a Discord role.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Role name (will be sanitized). |
required |
permissions
|
str
|
Permission bitfield string. |
PLAYER_ROLE_PERMISSION
|
color
|
int
|
Role color as integer. |
0
|
Returns:
| Type | Description |
|---|---|
dict
|
Created role data including 'id'. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
get_role(role_id)
¶
Get a role by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role_id
|
str
|
Discord role ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Role data dictionary. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
delete_role(role_id)
¶
Delete a Discord role.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role_id
|
str
|
Discord role ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
API response (usually empty on success). |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
create_channel(name, parent_id, role_id, gm_id)
¶
Create a Discord text channel with permissions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Channel name (will be sanitized). |
required |
parent_id
|
str
|
Parent category ID. |
required |
role_id
|
str
|
Player role ID for permission overwrites. |
required |
gm_id
|
str
|
GM user ID for permission overwrites. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Created channel data including 'id'. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
get_channel(channel_id)
¶
Get a channel by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_id
|
str
|
Discord channel ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Channel data dictionary. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
delete_channel(channel_id)
¶
Delete a Discord channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_id
|
str
|
Discord channel ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
API response (usually empty on success). |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
send_message(content, channel_id)
¶
Send a plain text message to a channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Message content. |
required |
channel_id
|
str
|
Target channel ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Created message data including 'id'. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
delete_message(message_id, channel_id)
¶
Delete a message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Discord message ID. |
required |
channel_id
|
str
|
Channel containing the message. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
API response (usually empty on success). |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
send_embed(embed, channel_id)
¶
Send an embed message to a channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embed
|
dict
|
Embed data dictionary. |
required |
channel_id
|
str
|
Target channel ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Created message data including 'id'. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
edit_embed(message_id, embed, channel_id)
¶
Edit an existing embed message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Message ID to edit. |
required |
embed
|
dict
|
New embed data dictionary. |
required |
channel_id
|
str
|
Channel containing the message. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Updated message data. |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
pin_message(message_id, channel_id)
¶
Pin a message to a channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
str
|
Message ID to edit. |
required |
channel_id
|
str
|
Target channel ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
API response (usually empty on success). |
Raises:
| Type | Description |
|---|---|
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
send_game_embed(game, embed_type='annonce', start=None, end=None, player=None, old_start=None, old_end=None, alert_message=None)
¶
Send or update a Discord embed for a game event.
This is a high-level method that builds and sends the appropriate embed based on the embed_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game
|
Game
|
Game model instance. |
required |
embed_type
|
str
|
Type of embed ('annonce', 'annonce_details', 'add-session', 'edit-session', 'del-session', 'register', 'alert'). |
'annonce'
|
start
|
Optional[datetime]
|
Session start datetime (for session embeds). |
None
|
end
|
Optional[datetime]
|
Session end datetime (for session embeds). |
None
|
player
|
Optional[str]
|
Player user ID (for register/alert embeds). |
None
|
old_start
|
Optional[datetime]
|
Previous session start (for edit-session). |
None
|
old_end
|
Optional[datetime]
|
Previous session end (for edit-session). |
None
|
alert_message
|
Optional[str]
|
Alert text (for alert embed). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Discord message ID string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If embed_type is unknown. |
DiscordAPIError
|
If the API request fails. |
Source code in website/services/discord.py
GameService
¶
Service layer for Game business logic.
Handles game creation, updates, status transitions, player registration, and Discord integration. Owns transaction boundaries (commits).
Source code in website/services/game.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
get_by_id(game_id)
¶
Get game by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game_id
|
int
|
Game ID. |
required |
Returns:
| Type | Description |
|---|---|
Game
|
Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
get_by_slug(slug)
¶
Get game by slug.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
URL-safe game identifier. |
required |
Returns:
| Type | Description |
|---|---|
Game
|
Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
get_by_slug_or_404(slug)
¶
Get game by slug or raise 404 (for Flask routes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
URL-safe game identifier. |
required |
Returns:
| Type | Description |
|---|---|
Game
|
Game instance. |
Raises:
| Type | Description |
|---|---|
NotFound
|
Flask 404 error. |
Source code in website/services/game.py
generate_slug(name, gm_name)
¶
Generate unique slug for a game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Game name. |
required |
gm_name
|
str
|
GM stable username (preferred) or display name (fallback). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Unique URL-safe slug. |
Source code in website/services/game.py
parse_game_type(type_value)
¶
Parse game type value from form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_value
|
str
|
Type string, possibly "specialevent- |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, Optional[int]]
|
Tuple of (game_type, special_event_id). |
Source code in website/services/game.py
create(data, gm_id, status='draft', create_resources=False)
¶
Create a new game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Game data dictionary from form. |
required |
gm_id
|
str
|
GM user ID. |
required |
status
|
str
|
Initial status (draft, open, closed). |
'draft'
|
create_resources
|
bool
|
Whether to create Discord resources (role, channel). |
False
|
Returns:
| Type | Description |
|---|---|
Game
|
Created Game instance. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If data is invalid. |
DiscordAPIError
|
If Discord resource creation fails. |
Source code in website/services/game.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
update(slug, data, user_id=None)
¶
Update an existing game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
data
|
dict
|
Updated game data. |
required |
user_id
|
str | None
|
ID of the user performing the update. |
None
|
Returns:
| Type | Description |
|---|---|
Game
|
Updated Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
ValidationError
|
If data is invalid. |
Source code in website/services/game.py
publish(slug, silent=False, user_id=None)
¶
Publish a draft game to Discord.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
silent
|
bool
|
If True, don't send announcement (set to closed instead of open). |
False
|
user_id
|
str | None
|
ID of the user performing the publish. |
None
|
Returns:
| Type | Description |
|---|---|
Game
|
Published Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
ValidationError
|
If game is already published or is full. |
DiscordAPIError
|
If Discord operations fail. |
Source code in website/services/game.py
close(slug, user_id=None)
¶
Close a game to new registrations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
user_id
|
str | None
|
ID of the user performing the close. |
None
|
Returns:
| Type | Description |
|---|---|
Game
|
Updated Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
reopen(slug, user_id=None)
¶
Reopen a closed game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
user_id
|
str | None
|
ID of the user performing the reopen. |
None
|
Returns:
| Type | Description |
|---|---|
Game
|
Updated Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
archive(slug, award_trophies=True, user_id=None)
¶
Archive a game and clean up Discord resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
award_trophies
|
bool
|
Whether to award trophies to participants. |
True
|
user_id
|
str | None
|
ID of the user performing the archive. |
None
|
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
delete(slug)
¶
Delete a game permanently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
register_player(slug, user_id, force=False)
¶
Register a player to a game (concurrent-safe).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
user_id
|
str
|
User ID to register. |
required |
force
|
bool
|
If True, bypass capacity and status checks. |
False
|
Returns:
| Type | Description |
|---|---|
Game
|
Updated Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
DuplicateRegistrationError
|
If user is already registered. |
GameFullError
|
If game is at capacity and force is False. |
GameClosedError
|
If game is closed and force is False. |
Source code in website/services/game.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
unregister_player(slug, user_id)
¶
Unregister a player from a game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug. |
required |
user_id
|
str
|
User ID to unregister. |
required |
Returns:
| Type | Description |
|---|---|
Game
|
Updated Game instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game or user doesn't exist. |
ValidationError
|
If user is not registered. |
Source code in website/services/game.py
clone(slug)
¶
Clone a game (return data dict for form prefill).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Game slug to clone. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict with game data for form. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If game doesn't exist. |
Source code in website/services/game.py
is_player(game, user_id)
¶
Check if a user is registered as a player in a game.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game
|
Game
|
Game instance. |
required |
user_id
|
str
|
User ID to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the user is a registered player. |
Source code in website/services/game.py
search(filters, page=1, per_page=20, user_payload=None)
¶
Search games with filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict
|
Search filters dict. |
required |
page
|
int
|
Page number. |
1
|
per_page
|
int
|
Items per page. |
20
|
user_payload
|
Optional[dict]
|
User auth payload. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[Game], int]
|
Tuple of (games list, total count). |
Source code in website/services/game.py
GameEventService
¶
Service layer for game event logging.
Provides transaction-safe event recording for the game audit trail.
Source code in website/services/game_event.py
log_event(action, game_id, description=None, user_id=None)
¶
Log a game event and commit the transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Event action type (create, edit, delete, etc.). |
required |
game_id
|
int
|
ID of the related game. |
required |
description
|
str | None
|
Optional human-readable description. |
None
|
user_id
|
str | None
|
Optional ID of the user that performed the action. |
None
|
Returns:
| Type | Description |
|---|---|
GameEvent
|
Created GameEvent instance. |
Source code in website/services/game_event.py
GameSessionService
¶
Service layer for GameSession operations.
Handles session creation, deletion, updates, and conflict detection.
Source code in website/services/game_session.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
create(game, start, end)
¶
Create a new game session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game
|
Game
|
Game instance to add the session to. |
required |
start
|
datetime
|
Session start datetime. |
required |
end
|
datetime
|
Session end datetime. |
required |
Returns:
| Type | Description |
|---|---|
GameSession
|
Created GameSession instance. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If start >= end. |
SessionConflictError
|
If the session overlaps with an existing one. |
Source code in website/services/game_session.py
delete(session)
¶
Delete a game session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
GameSession
|
GameSession instance to delete. |
required |
Source code in website/services/game_session.py
update(session, new_start, new_end)
¶
Update a session's start/end times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
GameSession
|
Existing GameSession instance. |
required |
new_start
|
datetime
|
New start datetime. |
required |
new_end
|
datetime
|
New end datetime. |
required |
Returns:
| Type | Description |
|---|---|
GameSession
|
Updated GameSession instance. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If new_start >= new_end. |
SessionConflictError
|
If new times overlap another session. |
Source code in website/services/game_session.py
get_by_id_or_404(session_id)
¶
Get session by ID or abort with 404.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session ID. |
required |
Returns:
| Type | Description |
|---|---|
GameSession
|
GameSession instance. |
Raises:
| Type | Description |
|---|---|
NotFound
|
Flask 404 error. |
Source code in website/services/game_session.py
find_in_range(start, end)
¶
Find all sessions within a date range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
datetime
|
Range start datetime. |
required |
end
|
datetime
|
Range end datetime. |
required |
Returns:
| Type | Description |
|---|---|
list[GameSession]
|
List of GameSession instances within the range. |
Source code in website/services/game_session.py
get_stats_for_period(year, month)
¶
Compute game statistics for a given month.
Aggregates session data into per-system, per-game counts for oneshots and campaigns, along with GM participation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int | None
|
Year to compute stats for, or None for current month. |
required |
month
|
int | None
|
Month to compute stats for, or None for current month. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys: base_day, last_day, num_os, num_campaign, |
dict
|
os_games, campaign_games, gm_names. |
Source code in website/services/game_session.py
SpecialEventService
¶
Service layer for SpecialEvent business logic.
Handles creation, updates, deletion, and retrieval of special events. Manages transaction boundaries and validation.
Source code in website/services/special_event.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
get_all(active_only=False)
¶
Get all special events, optionally filtered by active status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_only
|
bool
|
If True, only return active events. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[SpecialEvent]
|
List of SpecialEvent instances ordered by name. |
Source code in website/services/special_event.py
get_active()
¶
Get all active special events.
Convenience method for dropdowns and context processors.
Returns:
| Type | Description |
|---|---|
list[SpecialEvent]
|
List of active SpecialEvent instances ordered by name. |
Source code in website/services/special_event.py
get_by_id(id)
¶
Get special event by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Special event ID. |
required |
Returns:
| Type | Description |
|---|---|
SpecialEvent
|
SpecialEvent instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If special event with given ID doesn't exist. |
Source code in website/services/special_event.py
create(name, emoji=None, color=None, active=False)
¶
Create a new special event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the special event (must be unique). |
required |
emoji
|
str
|
Optional emoji for the event. |
None
|
color
|
int
|
Optional color as integer (e.g., 0xFF6600). |
None
|
active
|
bool
|
Whether the event is active. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
SpecialEvent
|
Created SpecialEvent instance. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If name already exists or validation fails. |
Source code in website/services/special_event.py
update(id, data)
¶
Update special event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Special event ID. |
required |
data
|
dict
|
Dictionary of fields to update. |
required |
Returns:
| Type | Description |
|---|---|
SpecialEvent
|
Updated SpecialEvent instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If special event doesn't exist. |
ValidationError
|
If name conflicts with existing event. |
Source code in website/services/special_event.py
delete(id)
¶
Delete special event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Special event ID. |
required |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If special event doesn't exist. |
Source code in website/services/special_event.py
SystemService
¶
Service layer for System (RPG game system) operations.
Handles CRUD operations with cache invalidation.
Source code in website/services/system.py
get_all()
¶
get_by_id(id)
¶
Get system by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
System ID. |
required |
Returns:
| Type | Description |
|---|---|
System
|
System instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If system does not exist. |
Source code in website/services/system.py
create(name, icon=None)
¶
Create a new game system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
System name (must be unique). |
required |
icon
|
str
|
Optional icon path. |
None
|
Returns:
| Type | Description |
|---|---|
System
|
Created System instance. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If name already exists. |
Source code in website/services/system.py
update(id, data)
¶
Update an existing system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
System ID. |
required |
data
|
dict
|
Dictionary of fields to update. |
required |
Returns:
| Type | Description |
|---|---|
System
|
Updated System instance. |
Source code in website/services/system.py
delete(id)
¶
Delete a system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
System ID. |
required |
TrophyService
¶
Service layer for Trophy business logic.
Handles awarding trophies, leaderboards, and user badge retrieval. Manages transaction boundaries and trophy-specific business rules.
Source code in website/services/trophy.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
get_by_id(trophy_id)
¶
Get trophy by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trophy_id
|
int
|
Trophy ID. |
required |
Returns:
| Type | Description |
|---|---|
Trophy
|
Trophy instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If trophy with given ID doesn't exist. |
Source code in website/services/trophy.py
get_all()
¶
award(user_id, trophy_id, amount=1)
¶
Award a trophy to a user.
Handles both unique and non-unique trophies according to business rules: - Unique trophies: Only awarded once (quantity = 1), additional awards are ignored - Non-unique trophies: Quantity is incremented by amount
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
User ID to award trophy to. |
required |
trophy_id
|
int
|
Trophy ID to award. |
required |
amount
|
int
|
Quantity to award (only applies to non-unique trophies). Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
UserTrophy
|
UserTrophy instance (created or updated). |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If trophy doesn't exist. |
Source code in website/services/trophy.py
get_leaderboard(trophy_id, limit=10)
¶
Get leaderboard for a specific trophy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trophy_id
|
int
|
Trophy ID to get leaderboard for. |
required |
limit
|
int
|
Maximum number of entries to return. Defaults to 10. |
10
|
Returns:
| Type | Description |
|---|---|
list[tuple[User, int]]
|
List of (User, total_quantity) tuples ordered by quantity descending. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If trophy doesn't exist. |
Source code in website/services/trophy.py
get_user_badges(user_id)
¶
Get all trophies/badges for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
User ID. |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of dicts with keys: name, icon, quantity. |
Source code in website/services/trophy.py
UserService
¶
Service layer for User operations.
Handles user retrieval, creation, and Discord profile management.
Source code in website/services/user.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
get_by_id(user_id)
¶
Get user by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
Returns:
| Type | Description |
|---|---|
User
|
User instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If user does not exist. |
Source code in website/services/user.py
get_or_create(user_id, name='Inconnu', username=None)
¶
Get an existing user or create a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
name
|
str
|
Display name for new users. Defaults to 'Inconnu'. |
'Inconnu'
|
username
|
str | None
|
Stable Discord username (optional). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[User, bool]
|
Tuple of (User, created) where created is True if the user was new. |
Source code in website/services/user.py
get_all()
¶
get_active_users()
¶
Get all users not marked as inactive.
Returns:
| Type | Description |
|---|---|
list[User]
|
List of active User instances. |
get_active_user_ids()
¶
Get IDs of all users not marked as inactive.
Lightweight query that avoids loading full ORM objects.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of active user ID strings. |
get_inactive_users()
¶
Get all users marked as inactive.
Returns:
| Type | Description |
|---|---|
list[User]
|
List of inactive User instances. |
get_inactive_user_ids()
¶
Get IDs of all users marked as inactive.
Lightweight query that avoids loading full ORM objects.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of inactive user ID strings. |
Source code in website/services/user.py
get_by_ids(ids)
¶
Get users by a list of IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
List of user ID strings. |
required |
Returns:
| Type | Description |
|---|---|
list[User]
|
List of User instances matching the given IDs. |
get_user_profile(user_id, force_refresh=False)
staticmethod
¶
Fetch a user's Discord profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
force_refresh
|
bool
|
If True, bypass cache and fetch from Discord. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with 'name', 'avatar', and optionally 'not_found' keys. |
Source code in website/services/user.py
mark_inactive(user_id)
¶
Mark a user as inactive (left the Discord server).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
Returns:
| Type | Description |
|---|---|
User
|
Updated User instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If user does not exist. |
Source code in website/services/user.py
clear_inactive(user_id)
¶
Clear the inactive flag for a user (they have rejoined).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
Discord user ID. |
required |
Returns:
| Type | Description |
|---|---|
User
|
Updated User instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If user does not exist. |
Source code in website/services/user.py
VttService
¶
Service layer for Vtt (virtual tabletop) operations.
Handles CRUD operations with cache invalidation.
Source code in website/services/vtt.py
get_all()
¶
get_by_id(id)
¶
Get VTT by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
VTT ID. |
required |
Returns:
| Type | Description |
|---|---|
Vtt
|
Vtt instance. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If VTT does not exist. |
Source code in website/services/vtt.py
create(name, icon=None)
¶
Create a new VTT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
VTT name (must be unique). |
required |
icon
|
str
|
Optional icon path. |
None
|
Returns:
| Type | Description |
|---|---|
Vtt
|
Created Vtt instance. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If name already exists. |
Source code in website/services/vtt.py
update(id, data)
¶
Update an existing VTT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
VTT ID. |
required |
data
|
dict
|
Dictionary of fields to update. |
required |
Returns:
| Type | Description |
|---|---|
Vtt
|
Updated Vtt instance. |
Source code in website/services/vtt.py
delete(id)
¶
Delete a VTT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
VTT ID. |
required |