-
-
Notifications
You must be signed in to change notification settings - Fork 41
feat: add assets/data for data files, refactor facts, improve substitutions, add __init__.py into tux/extensions #945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ml, implement pulling facts from apis, implement substitutions feat(assets/data): create assets/data for future use feat(substitutions): move activity substitutions into its own file for easy use in other files fix(extensions): add __init__.py into tux/extensions to fix some issues
Reviewer's GuideThis PR externalizes static fact data into a TOML file, refactors the Fact cog to load and fetch facts dynamically (including API support, autocomplete and usage generation), introduces a global substitution utility for templating placeholders across facts and activities, simplifies the activity handler by removing inline substitution logic and adding logging, and adds the missing init.py in tux/extensions to resolve package initialization issues. Sequence diagram for fetching a fact with substitutions and API supportsequenceDiagram
actor User
participant DiscordBot as Tux
participant FactCog as Fact
participant Substitution as handle_substitution
participant API as ExternalFactAPI
User->>DiscordBot: /fact [category]
DiscordBot->>FactCog: fact(ctx, fact_type)
FactCog->>FactCog: _fetch_fact(fact_type)
alt fact_api_url present
FactCog->>API: GET fact_api_url
API-->>FactCog: {fact_api_field: fact}
FactCog->>Substitution: handle_substitution(bot, fact)
Substitution-->>FactCog: substituted_fact
else
FactCog->>Substitution: handle_substitution(bot, random_fact)
Substitution-->>FactCog: substituted_fact
end
FactCog->>DiscordBot: send embed with substituted_fact
DiscordBot-->>User: Fact embed
Class diagram for Fact cog refactor and substitution utilityclassDiagram
class Fact {
- bot: Tux
- facts_data: dict[str, dict[str, Any]]
+ __init__(bot: Tux)
+ _load_facts() None
+ _fetch_fact(fact_type: str) tuple[str, str] | None
+ fact_type_autocomplete(interaction, current) list[app_commands.Choice[str]]
+ fact(ctx, fact_type: str = "random") None
}
class handle_substitution {
+ handle_substitution(bot: Tux, text: str)
}
Fact --> "uses" handle_substitution : calls
class Tux
Fact --> Tux : has reference
handle_substitution --> Tux : uses
Class diagram for new substitutions utilityclassDiagram
class handle_substitution {
+ handle_substitution(bot: Tux, text: str)
- _get_member_count(bot: Tux)
}
class Tux
handle_substitution --> Tux : uses
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @electron271 - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #945 +/- ##
=====================================
Coverage 9.32% 9.32%
=====================================
Files 121 122 +1
Lines 10286 10327 +41
Branches 1259 1267 +8
=====================================
+ Hits 959 963 +4
- Misses 9226 9262 +36
- Partials 101 102 +1
*This pull request uses carry forward flags. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Description
feat(fact.py): refactor facts to pull facts from assets/data/facts.toml, implement pulling facts from apis, implement substitutions
feat(assets/data): create assets/data for future use
feat(substitutions): move activity substitutions into its own file for easy use in other files
fix(extensions): add init.py into tux/extensions to fix some issues
Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
ran facts with multiple different uses
tested substitutions
worked on an extension
Summary by Sourcery
Refactor the facts feature to load data from an external TOML file, support API-driven and static facts with placeholder substitutions, add autocomplete for fact categories, extract substitution logic into a shared module, and prepare assets/data for future use and extensions.
New Features:
Enhancements:
Chores: