Skip to content

Commit c094fa6

Browse files
Make Kattbot slightly dumb again
Only responds when spoken to.
1 parent 4f7e3bb commit c094fa6

File tree

2 files changed

+10
-45
lines changed

2 files changed

+10
-45
lines changed

src/Kattbot/NotificationHandlers/KattGptMessageHandler.cs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class KattGptMessageHandler : BaseNotificationHandler,
2929

3030
private const int MaxTotalTokens = 24_576;
3131
private const int MaxTokensToGenerate = 960; // Roughly the limit of 2 Discord messages
32+
3233
private const string MessageSplitToken = "[cont.] ";
33-
private const string RecipientMarkerToYou = "[to you]";
34-
private const string RecipientMarkerToOthers = "[to others]";
34+
3535
private const string MessageToolUseTemplate = "`Kattbot used: {0}`";
3636

3737
private const string GptImageModel = "gpt-image-1";
@@ -85,26 +85,16 @@ public async Task Handle(MessageCreatedNotification notification, CancellationTo
8585
systemPromptsMessages,
8686
chatCompletionFunction);
8787

88-
bool shouldReplyToMessage = ShouldReplyToMessage(message);
89-
90-
string recipientMarker = shouldReplyToMessage
91-
? RecipientMarkerToYou
92-
: RecipientMarkerToOthers;
93-
9488
// Add the new message from notification
9589
string newMessageUser = author.GetDisplayName();
9690
string newMessageContent = message.SubstituteMentions();
9791

9892
ChatCompletionMessage newUserMessage =
99-
ChatCompletionMessage.AsUser($"{newMessageUser}{recipientMarker}: {newMessageContent}");
93+
ChatCompletionMessage.AsUser($"{newMessageUser}: {newMessageContent}");
10094

10195
newContextMessages.Add(newUserMessage);
10296

103-
if (!shouldReplyToMessage)
104-
{
105-
channelContext.AddMessages(newContextMessages);
106-
return;
107-
}
97+
channelContext.AddMessages(newContextMessages);
10898

10999
await channel.TriggerTypingAsync();
110100

@@ -379,31 +369,7 @@ private bool ShouldHandleMessage(DiscordMessage message)
379369

380370
if (channelOptions == null) return false;
381371

382-
// if the channel is not always on, handle the message
383-
if (!channelOptions.AlwaysOn) return true;
384-
385-
// otherwise check if the message does not start with the MetaMessagePrefix
386-
string[] metaMessagePrefixes = _kattGptOptions.AlwaysOnIgnoreMessagePrefixes;
387-
bool messageStartsWithMetaMessagePrefix = metaMessagePrefixes.Any(messageContent.StartsWith);
388-
389-
// if it does, return false
390-
return !messageStartsWithMetaMessagePrefix;
391-
}
392-
393-
/// <summary>
394-
/// Checks if KattGpt should reply to the message.
395-
/// </summary>
396-
/// <param name="message">The message.</param>
397-
/// <returns>True if KattGpt should reply.</returns>
398-
private bool ShouldReplyToMessage(DiscordMessage message)
399-
{
400-
DiscordChannel channel = message.Channel!;
401-
402-
ChannelOptions? channelOptions = _kattGptService.GetChannelOptions(channel);
403-
404-
if (channelOptions == null) return false;
405-
406-
// if the channel is not always on
372+
// if the channel is not always on i.e. requires @mention or Reply
407373
if (!channelOptions.AlwaysOn)
408374
{
409375
// check if the current message is a reply to kattbot
@@ -419,7 +385,7 @@ private bool ShouldReplyToMessage(DiscordMessage message)
419385

420386
// otherwise check if the message does not start with the MetaMessagePrefix
421387
string[] metaMessagePrefixes = _kattGptOptions.AlwaysOnIgnoreMessagePrefixes;
422-
bool messageStartsWithMetaMessagePrefix = metaMessagePrefixes.Any(message.Content.TrimStart().StartsWith);
388+
bool messageStartsWithMetaMessagePrefix = metaMessagePrefixes.Any(messageContent.StartsWith);
423389

424390
// if it does, return false
425391
return !messageStartsWithMetaMessagePrefix;

src/Kattbot/appsettings.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
"",
3535
"**Communication in Discord Channels:**",
3636
"- Interaction: Only engage in conversations when directly addressed by users.",
37-
"- Addressing: Messages from users will be prefixed with their name and the recipient marker ([to others] or [to you]).",
38-
" - Example: \"Alice[to others]: Hello, everyone! What’s up?\".",
39-
" - Example: \"Bob[to you]: Hello, how are you?\".",
40-
"- Response: Respond without prefixing your message with your name or a recipient marker. Use the name of the person addressing you to make the interaction more personal.",
37+
"- Addressing: Messages from users will be prefixed with their name.",
38+
" - Example: \"Bob: Hello, how are you?\".",
39+
"- Response: Respond using the name of the person addressing you to make the interaction more personal. Subsequent messages may omit the person's name.",
4140
" - Example: \"Hey, Bob! I’m doing quite well. How about you?\"",
4241
"",
4342
"**General Communication Guidelines:**",
@@ -50,7 +49,7 @@
5049
"- Image Requests: Generate images only when requested by users.",
5150
"- When sharing an image that you generate, do not include textual indicators like \"[Attaches image]\" or \"[Generated image]\" within the message. The generated image is automatically added to your reply.",
5251
" - Example: ",
53-
" - User: \"John[to you]: Can you draw a cat sitting on a moon?\"",
52+
" - User: \"John: Can you draw a cat sitting on a moon?\"",
5453
" - Kattbot: \"Sure thing, John! Here’s your cat lounging on a moon!\" [This message contains the generated image]"
5554
],
5655
"Templates": [

0 commit comments

Comments
 (0)