@@ -2,6 +2,18 @@ const { getRandomWord, scrambleWord } = require("../constants/words.js");
22const minecraftCommand = require ( "../../contracts/minecraftCommand.js" ) ;
33const getWord = ( message ) => message . split ( " " ) . pop ( ) ;
44
5+ const getUsername = ( message ) => {
6+ const match = message . match (
7+ / ^ (?: (?: \[ (?< rank > [ ^ \] ] + ) \] ) ? (?: (?< username > \w + ) (?: \[ (?< guildRank > [ ^ \] ] + ) \] ) ? : ) ? ) ? (?< message > .+ ) $ /
8+ ) ;
9+
10+ if ( ! match ) {
11+ return null ;
12+ }
13+
14+ return match . groups . username ;
15+ } ;
16+
517const cooldowns = new Map ( ) ;
618
719class unscrambleCommand extends minecraftCommand {
@@ -23,7 +35,6 @@ class unscrambleCommand extends minecraftCommand {
2335
2436 async onCommand ( username , message ) {
2537 try {
26- const userUsername = username ;
2738 const length = this . getArgs ( message ) [ 0 ] ;
2839 const answer = getRandomWord ( length ) ;
2940 const scrambledWord = scrambleWord ( answer ) ;
@@ -44,7 +55,9 @@ class unscrambleCommand extends minecraftCommand {
4455 cooldowns . set ( this . name , Date . now ( ) ) ;
4556 const listener = ( username , message ) => {
4657 if ( getWord ( message ) === answer ) {
47- this . send ( `${ userUsername } guessed it right! Time elapsed: ${ ( Date . now ( ) - startTime ) . toLocaleString ( ) } ms!` ) ;
58+ this . send (
59+ `${ getUsername ( message ) } guessed it right! Time elapsed: ${ ( Date . now ( ) - startTime ) . toLocaleString ( ) } ms!`
60+ ) ;
4861 bot . removeListener ( "chat" , listener ) ;
4962 answered = true ;
5063 cooldowns . delete ( this . name ) ;
0 commit comments