-
Notifications
You must be signed in to change notification settings - Fork 0
/
clyde.go
44 lines (35 loc) · 996 Bytes
/
clyde.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"os"
"strings"
"github.com/charmbracelet/glamour"
"github.com/diamondburned/arikawa/v3/discord"
)
func AskClyde(prompt string, instructions string) {
if ClydeChannel == 0 {
id, err := discord.ParseSnowflake(os.Getenv("CLYDE_CHANNEL_ID"))
if err != nil {
tui.Send(logMsg{Msg: "Unable to parse channel id", Type: Error})
}
ClydeChannel = discord.ChannelID(id)
}
if strings.Contains(prompt, "@cb") {
prompt = strings.ReplaceAll(prompt, "@cb", ReadClipboard())
}
if len(instructions) > 0 {
prompt += ".\n" + instructions
}
Session.SendMessage(ClydeChannel, prompt)
}
func FormatClydeResponse(msg string) (string, string) {
parsed := strings.ReplaceAll(msg, fmt.Sprintf("<@!%s>", CurrentUserID), "`@You`")
var md string
if os.Getenv("GLAMOUR_STYLE") != "" {
md, _ = glamour.RenderWithEnvironmentConfig(parsed)
} else {
md, _ = glamour.Render(parsed, "dark")
}
trimmed := strings.Trim(md, "\n") + "\n"
return parsed, trimmed
}