@@ -6,7 +6,7 @@ import redis from "../components/redis";
66
77export const info = {
88 command : "update" ,
9- description : "Pull changes from the remote repository." ,
9+ description : "Pull changes from the remote repository and show commit info ." ,
1010 usage : "update" ,
1111 example : "update" ,
1212 role : "user" ,
@@ -17,10 +17,29 @@ const execPromise = util.promisify(exec);
1717
1818export default async function ( msg : Message ) {
1919 if ( ! / ^ u p d a t e / i. test ( msg . body ) ) return ;
20- const { stdout, stderr } = await execPromise ( "git pull" ) ;
2120
22- if ( stdout ) log . info ( "Update" , `git pull stdout:\n${ stdout } ` ) ;
23- if ( stderr ) log . warn ( "Update" , `git pull stderr:\n${ stderr } ` ) ;
21+ try {
22+ const { stdout, stderr } = await execPromise ( "git pull" ) ;
23+ if ( stdout ) log . info ( "Update" , `git pull stdout:\n${ stdout } ` ) ;
24+ if ( stderr ) log . warn ( "Update" , `git pull stderr:\n${ stderr } ` ) ;
2425
25- await msg . reply ( stdout || stderr ) ;
26+ const { stdout : commitInfo } = await execPromise (
27+ 'git log -1 --pretty=format:"%h - %s (%an, %ar)"' ,
28+ ) ;
29+
30+ const text = `
31+ \`Canis updated\`
32+
33+ ${ commitInfo }
34+ ` ;
35+
36+ const response = stdout . includes ( "Already up to date" )
37+ ? "Already up to date."
38+ : text ;
39+
40+ await msg . reply ( response ) ;
41+ } catch ( err : any ) {
42+ log . error ( "Update" , err . message || err ) ;
43+ await msg . reply ( `❌ Update failed:\n${ err . message || err } ` ) ;
44+ }
2645}
0 commit comments