File tree 1 file changed +29
-1
lines changed
packages/client-discord/src
1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -389,11 +389,16 @@ export class MessageManager {
389
389
discordMessageHandlerTemplate ,
390
390
} ) ;
391
391
392
+ // simulate discord typing while generating a response
393
+ const stopTyping = this . simulateTyping ( message )
394
+
392
395
const responseContent = await this . _generateResponse (
393
396
memory ,
394
397
state ,
395
398
context
396
- ) ;
399
+ ) . finally ( ( ) => {
400
+ stopTyping ( )
401
+ } ) ;
397
402
398
403
responseContent . text = responseContent . text ?. trim ( ) ;
399
404
responseContent . inReplyTo = stringToUuid (
@@ -1307,4 +1312,27 @@ export class MessageManager {
1307
1312
const data = await response . json ( ) ;
1308
1313
return data . username ;
1309
1314
}
1315
+
1316
+ /**
1317
+ * Simulate discord typing while generating a response;
1318
+ * returns a function to interrupt the typing loop
1319
+ *
1320
+ * @param message
1321
+ */
1322
+ private simulateTyping ( message : DiscordMessage ) {
1323
+ let typing = true ;
1324
+
1325
+ const typingLoop = async ( ) => {
1326
+ while ( typing ) {
1327
+ await message . channel . sendTyping ( ) ;
1328
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) ) ;
1329
+ }
1330
+ } ;
1331
+
1332
+ typingLoop ( ) ;
1333
+
1334
+ return function stopTyping ( ) {
1335
+ typing = false
1336
+ }
1337
+ }
1310
1338
}
You can’t perform that action at this time.
0 commit comments