Module Cogs & Commands¶
The ModulSearch Cog (src.oscar.cogs.modul) is the central interaction point. It manages the connection between Discord slash commands and the university module data.
Architecture¶
classDiagram
class ModulSearch {
+bot : Bot
+catalogue : Catalogue
+module_autocomplete(interaction, current)
+search_module(interaction, module_name)
+filter(interaction)
+plan(interaction)
+start(interaction)
+feedback(interaction)
}
class Catalogue {
-_module_catalogue : list
-_modules : list~ModuleMatch~
+find_match(module_name)
+get_module_list()
}
class Views {
<<Interface>>
ModuleView
SelectView
SemesterplanView
FeedbackView
StartView
}
ModulSearch --> Catalogue : queries
ModulSearch ..> Views : creates
ModulSearch Class¶
The class initializes the Catalogue (cached module list) on startup using the 2018 view ID to ensure fast data retrieval.
src.oscar.cogs.modul.ModulSearch ¶
Bases: Cog
Class for module related commands
Source code in src/oscar/cogs/modul.py
search_module
async
¶
Command for searching a single module by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
automatically provided interaction object. |
required |
modul
|
str
|
The id of a picked suggestion, or a module title typed by hand. |
required |
Source code in src/oscar/cogs/modul.py
filter
async
¶
Command to open the filter dialog for module filtering by different criteria
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
automatically provided interaction object. |
required |
Source code in src/oscar/cogs/modul.py
plan
async
¶
Command to open the semester plan dialog for the user
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
automatically provided interaction object. |
required |
Source code in src/oscar/cogs/modul.py
start
async
¶
Command to open the start dialog for the user
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
automatically provided interaction object. |
required |
Source code in src/oscar/cogs/modul.py
feedback
async
¶
Command to open the feedback dialog for the user
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interaction
|
Interaction
|
automatically provided interaction object. |
required |
Source code in src/oscar/cogs/modul.py
Module Setup¶
Required function for discord.py to load this extension.
src.oscar.cogs.modul.setup
async
¶
Technical Implementation Details¶
module_autocomplete¶
Note: This is a helper method bound via the
@autocompletedecorator to the/modulecommand.
Provides live suggestions while the user types.
- Logic: Uses the
Catalogueclass to perform a fuzzy search (viarapidfuzz) on cached module titles. - Performance: Limits results to the top 5 matches to ensure UI responsiveness.
- Ambiguity: Some modules share a title. Such an entry shows its id in brackets, for example
Introduction to Simulation (100372). A unique title is shown as it is. - Value: Every choice carries the module id as its value.
resolve_moduleturns that id back into a module, so a picked entry always opens the module the user saw. A title typed by hand is still looked up withModule.from_name. - Parameters:
interaction: The Discord interaction context.current(str): The partial string typed by the user.
Smart Semester Detection¶
The commands /start and /feedback feature automatic context detection. They iterate through the user's roles to find a pattern matching r"Semester\s+(\d+)".
- Goal: Pre-fills the semester selection in the UI (e.g.,
StartVieworFeedbackView) to reduce user friction. - Fallback: If no role matches, the semester defaults to
-1, prompting a manual selection.
Command Mapping¶
| Slash Command | Python Method | View Class |
|---|---|---|
/module |
search_module |
ModuleView |
/filter |
filter |
SelectView |
/semesterplan |
plan |
SemesterplanView |
/feedback |
feedback |
FeedbackView |
/start |
start |
StartView |