@@ -10,8 +10,10 @@ import path from "path";
1010import { startServer } from "./server" ;
1111
1212const commandPrefix = process . env . COMMAND_PREFIX || "!" ;
13+ const commandPrefixLess = process . env . COMMAND_PREFIX_LESS === "true" ;
1314const botName = process . env . PROJECT_CANIS_ALIAS || "Canis" ;
1415const debug = process . env . DEBUG === "true" ;
16+ const autoReload = process . env . AUTO_RELOAD === "true" ;
1517const port = process . env . PORT || 3000 ;
1618
1719log . info ( "Bot" , `Welcome to ${ botName } !` ) ;
@@ -36,20 +38,21 @@ const loadCommand = (file: string) => {
3638 log . info ( "Loader" , `Loaded command: ${ commandModule . command } ` ) ;
3739 }
3840 }
39- }
41+ } ;
4042
4143fs . readdirSync ( commandsPath ) . forEach ( loadCommand ) ;
4244
4345// Watch for changes
44- fs . watch ( commandsPath , ( eventType , filename ) => {
45- if ( filename && / \. j s $ | \. t s $ / . test ( filename ) ) {
46- try {
47- loadCommand ( filename ) ;
48- } catch ( err ) {
49- log . error ( "Loader" , `Failed to reload command: ${ filename } ` , err ) ;
46+ if ( autoReload )
47+ fs . watch ( commandsPath , ( eventType , filename ) => {
48+ if ( filename && / \. j s $ | \. t s $ / . test ( filename ) ) {
49+ try {
50+ loadCommand ( filename ) ;
51+ } catch ( err ) {
52+ log . error ( "Loader" , `Failed to reload command: ${ filename } ` , err ) ;
53+ }
5054 }
51- }
52- } ) ;
55+ } ) ;
5356
5457client . on ( "qr" , ( qr ) => {
5558 // Generate and scan this code with your phone
@@ -72,25 +75,20 @@ client.initialize();
7275
7376const messageEvent = ( msg : Message ) => {
7477 const prefix = ! msg . body . startsWith ( commandPrefix ) ;
75- if ( prefix ) return ;
78+ if ( ! commandPrefixLess && prefix ) return ;
7679 if ( msg . fromMe && prefix ) return ; // Ignore messages sent by the bot itself without prefix
7780
7881 const keyWithPrefix = msg . body . split ( " " ) [ 0 ] ;
7982 const key = keyWithPrefix . startsWith ( commandPrefix )
8083 ? keyWithPrefix . slice ( commandPrefix . length )
8184 : keyWithPrefix ;
8285 const handler = commands [ key ] ;
83-
84- if ( ! handler && debug ) {
85- log . warn ( "Command" , `No handler found for command: ${ key } ` ) ;
86- msg . reply (
87- `Unknown command: ${ key } . Type ${ commandPrefix } help for a list of commands.`
88- ) ;
89- return ;
90- }
91-
86+
87+ if ( ! handler ) return ;
88+ msg . body = msg . body . slice ( keyWithPrefix . length ) . trim ( ) ;
89+
9290 if ( debug ) log . info ( "Message" , msg . body . slice ( 0 , 255 ) ) ;
9391 handler ( msg ) ;
9492} ;
9593
96- export { commands }
94+ export { commands } ;
0 commit comments