diff --git a/plugins/notes.py b/plugins/notes.py index 2f63f37..fd18472 100644 --- a/plugins/notes.py +++ b/plugins/notes.py @@ -168,40 +168,24 @@ class NoteTaking: self.User = Query() self.log = logging.getLogger(__name__) - - @command(aliases=['notes'], public=True) + @command(aliases=['notes'], public=True, options_first=False, use_shlex=True) async def note(self, mask, target, args): """ - Unified note command. - + %%note %%note today [...] - %%note daily [--date ] [...] - %%note general [--tags <tags>] [<content>...] - %%note list [<type>] + %%note daily [<content>...] [--date=<date>] + %%note general <title> [<content>...] [--tags <tags>] + %%note list <type> %%note search <type> <keyword> %%note summary - - Options: - --date <date> Date in YYYY-MM-DD format. - --tags <tags> Tags for a general note. - <type> Either 'daily' or 'general'. - <title> Title for a general note. - <content> Content to update the note. - <keyword> Keyword to search in notes. """ + # If no subcommand is provided, show the help message. + if not any(args.get(key) for key in ('today', 'daily', 'general', 'list', 'search', 'summary')): + self._show_help(target) + return + try: - if not args: - # Display the help message if no arguments are provided - help_msg = ircstyle.style("Usage: !note <subcommand> [options]\n", fg="red", bold=True) - help_msg += "Subcommands:\n" - help_msg += ircstyle.style("today", fg="yellow") + " - View or update today's daily note.\n" - help_msg += ircstyle.style("daily [--date <date>]", fg="yellow") + " - View or update a daily note for a specific date (default is today).\n" - help_msg += ircstyle.style("general <title> [--tags <tags>]", fg="yellow") + " - View or update a general note with the given title. Optionally, specify tags.\n" - help_msg += ircstyle.style("list [daily|general]", fg="yellow") + " - List all notes of a specific type (either 'daily' or 'general').\n" - help_msg += ircstyle.style("search <type> <keyword>", fg="yellow") + " - Search for a keyword in notes of a specific type.\n" - help_msg += ircstyle.style("summary", fg="yellow") + " - Display a summary of note counts.\n" - self.bot.privmsg(target, help_msg) - elif args.get('today'): + if args.get('today'): await self._note_today(mask, target, args) elif args.get('daily'): await self._note_daily(mask, target, args) @@ -213,9 +197,6 @@ class NoteTaking: await self._note_search(target, args) elif args.get('summary'): await self._note_summary(target) - else: - help_msg = ircstyle.style("Invalid subcommand! Use !note for a list of available commands.\n", fg="red", bold=True) - self.bot.privmsg(target, help_msg) except Exception as e: self.bot.log.error(f"Error processing note command: {e}", exc_info=True) self.bot.privmsg( @@ -223,6 +204,21 @@ class NoteTaking: ircstyle.style(f"❌ Error processing command: {e}", fg="red", bold=True) ) + def _show_help(self, target): + help_lines = [ + ircstyle.style("Usage: !note <subcommand> [options]", fg="red", bold=True), + "Subcommands:", + f"{ircstyle.style(' today', fg='yellow')} - View or update today's daily note.", + f"{ircstyle.style(' daily [--date <date>]', fg='yellow')} - View or update a daily note for a specific date (default is today).", + f"{ircstyle.style(' general <title> [--tags <tags>]', fg='yellow')} - View or update a general note with the given title. Optionally, specify tags.", + f"{ircstyle.style(' list [daily|general]', fg='yellow')} - List all notes of a specific type.", + f"{ircstyle.style(' search <type> <keyword>', fg='yellow')} - Search for a keyword in notes of a specific type.", + f"{ircstyle.style(' summary', fg='yellow')} - Display a summary of note counts.", + ] + + for line in help_lines: + self.bot.privmsg(target, line) + async def _note_today(self, mask, target, args): """ Handle the 'today' subcommand for daily notes. @@ -289,6 +285,7 @@ class NoteTaking: return content_list = args.get('<content>') + try: note = self._get_daily_note(day) if content_list: