diff --git a/src/rdrama/services/CommentParser.ts b/src/rdrama/services/CommentParser.ts index fa003c8..2a73f11 100644 --- a/src/rdrama/services/CommentParser.ts +++ b/src/rdrama/services/CommentParser.ts @@ -2,27 +2,21 @@ import { Comment } from '../models/Comment'; export class CommentParser { /** - * Extracts Reddit usernames from the body of a single comment. + * Parses commands from the body of a single comment triggered by !!Oregon. * @param comment A single Comment object to be processed. - * @returns An array of unique Reddit usernames found in the comment. + * @returns An object containing the command and its arguments, if any. */ - public static extractUsernames(comment: Comment): string[] { - const regexPattern: RegExp = /(^|\s|\\r\\n|\\t|[".,;(){}\[\]!?@#])(\/?u\/[a-zA-Z0-9_]+)/g; - const foundUsernames: Set = new Set(); + public static parseCommand(comment: Comment): { command: string, args: string[] } { + const commandTrigger: RegExp = /!!Oregon\s+(\w+)(?:\s+(.*))?/i; + const match = comment.body.match(commandTrigger); - const matches = comment.body.match(regexPattern); - if (matches) { - matches.forEach(match => { - // Ensure the username is captured in a standardized format - const usernameMatch = match.trim().match(/\/?u\/([a-zA-Z0-9_]+)/); - if (usernameMatch) { - // Standardize to "username" format - const username = `${usernameMatch[1].toLowerCase()}`; - foundUsernames.add(username); - } - }); + if (match) { + const command = match[1].toLowerCase(); + const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : []; + return { command, args }; } - return Array.from(foundUsernames); + // No command found + return { command: '', args: [] }; } }