aboutsummaryrefslogtreecommitdiff
path: root/cmd/mimi
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-05-31 14:36:31 -0400
committerXe Iaso <me@xeiaso.net>2024-05-31 14:36:31 -0400
commitd916729a65fe60a09e010dcee6ca7345afaa2085 (patch)
tree327eea2bf2d9c3f0d76430f08f6e3c74897d2b4b /cmd/mimi
parente7a5a25e62fb05ffbfbf66e846093fdf1216944c (diff)
downloadx-d916729a65fe60a09e010dcee6ca7345afaa2085.tar.xz
x-d916729a65fe60a09e010dcee6ca7345afaa2085.zip
cmd/mimi/modules/discord/flyio: remove some dead code that I regret making
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/mimi')
-rw-r--r--cmd/mimi/modules/discord/flyio/flyio.go177
1 files changed, 2 insertions, 175 deletions
diff --git a/cmd/mimi/modules/discord/flyio/flyio.go b/cmd/mimi/modules/discord/flyio/flyio.go
index f273b9d..3541b8b 100644
--- a/cmd/mimi/modules/discord/flyio/flyio.go
+++ b/cmd/mimi/modules/discord/flyio/flyio.go
@@ -1,190 +1,17 @@
package flyio
import (
- "context"
- "encoding/json"
- "flag"
- "fmt"
- "log/slog"
-
"github.com/bwmarrin/discordgo"
- "google.golang.org/protobuf/types/known/emptypb"
- "within.website/x/cmd/mimi/internal"
- "within.website/x/proto/mimi/statuspage"
- "within.website/x/web/ollama"
-)
-
-var (
- flyDiscordGuild = flag.String("fly-discord-guild", "1194719413732130866", "fly discord guild ID")
- flyDiscordTeamID = flag.String("fly-discord-team", "1197660035212394657", "fly discord team ID")
)
-func p[T any](t T) *T {
- return &t
-}
-
-func mentionsTeam(m *discordgo.MessageCreate) bool {
- for _, u := range m.MentionRoles {
- if u == *flyDiscordTeamID {
- return true
- }
- }
-
- return false
-}
-
type Module struct {
- ola *ollama.Client
- model string
- sess *discordgo.Session
+ sess *discordgo.Session
}
func New() *Module {
- return &Module{
- ola: internal.OllamaClient(),
- model: internal.OllamaModel(),
- }
-}
-
-func (m *Module) judgeIfAboutFlyIO(ctx context.Context, msg string) (bool, error) {
- resp, err := m.ola.Chat(ctx, &ollama.CompleteRequest{
- Model: m.model,
- Messages: []ollama.Message{
- {
- Role: "system",
- Content: "You will be given messages that may be about Fly.io or deploying apps to fly.io in programming languages such as Go. If a message is about Fly.io in some way, then reply with a JSON object {\"about_fly.io\": true}. If it is not, then reply {\"about_fly.io\": false}.",
- },
- {
- Role: "user",
- Content: fmt.Sprintf("Is this message about Fly.io, or Fly?\n\n%s", msg),
- },
- },
- Format: p("json"),
- Stream: false,
- })
- if err != nil {
- return false, fmt.Errorf("ollama: error chatting: %w", err)
- }
-
- slog.Info("checked if about fly.io", "response", resp.Message.Content)
-
- type aboutFlyIO struct {
- AboutFlyIO bool `json:"about_fly.io"`
- }
-
- var af aboutFlyIO
- if err := json.Unmarshal([]byte(resp.Message.Content), &af); err != nil {
- return false, fmt.Errorf("ollama: error unmarshaling response: %w", err)
- }
-
- slog.Debug("checked if about fly.io", "about_fly.io", af.AboutFlyIO, "message", msg)
- return af.AboutFlyIO, nil
+ return &Module{}
}
func (m *Module) Register(s *discordgo.Session) {
- s.AddHandler(m.HandleMentionFlyIO)
- s.AddHandler(m.ReactionAddFlyIO)
-
m.sess = s
}
-
-func (m *Module) scoldMessage(ctx context.Context) (string, error) {
- resp, err := m.ola.Chat(ctx, &ollama.CompleteRequest{
- Model: m.model,
- Messages: []ollama.Message{
- {
- Role: "system",
- Content: "Your job is to redirect questions about Fly.io to the official community forums at https://community.fly.io. Include the link https://community.fly.io in all your replies. Always assist with care, respect, and truth. Respond with utmost utility yet securely. Avoid harmful, unethical, prejudiced, or negative content. Ensure replies promote fairness and positivity. Be terse. ",
- },
- {
- Role: "user",
- Content: "Tell me to go to https://community.fly.io/ and ask my question there. I am not in an official Fly.io support channel, but I may hear from someone here.",
- },
- },
- Stream: false,
- })
- if err != nil {
- return "", fmt.Errorf("ollama: error chatting: %w", err)
- }
-
- return resp.Message.Content, nil
-}
-
-func (m *Module) HandleMentionFlyIO(s *discordgo.Session, mc *discordgo.MessageCreate) {
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
-
- if mc.Author.ID == s.State.User.ID {
- return
- }
-
- if mc.Author.Bot {
- return
- }
-
- if mc.GuildID != *flyDiscordGuild {
- return
- }
-
- if mc.Content == "" {
- return
- }
-
- switch {
- case mentionsTeam(mc):
- default:
- return
- }
-
- aboutFlyIO, err := m.judgeIfAboutFlyIO(ctx, mc.Content)
- if err != nil {
- slog.Error("cannot judge message", "error", err)
- return
- }
-
- if !aboutFlyIO {
- return
- }
-
- resp, err := m.scoldMessage(ctx)
- if err != nil {
- slog.Error("cannot fabricate scold message", "error", err)
- return
- }
-
- if _, err := s.ChannelMessageSendReply(mc.ChannelID, resp, mc.Reference()); err != nil {
- slog.Error("cannot send scold message", "error", err)
- return
- }
-}
-
-func (m *Module) ReactionAddFlyIO(s *discordgo.Session, mra *discordgo.MessageReactionAdd) {
- if mra.GuildID != *flyDiscordGuild {
- return
- }
-
- if mra.Emoji.Name != "👉" {
- return
- }
-
- msg, err := s.ChannelMessage(mra.ChannelID, mra.MessageID)
- if err != nil {
- slog.Error("cannot get message", "error", err)
- return
- }
-
- resp, err := m.scoldMessage(context.Background())
- if err != nil {
- slog.Error("cannot fabricate scold message", "error", err)
- return
- }
-
- if _, err := s.ChannelMessageSendReply(mra.ChannelID, resp, msg.Reference()); err != nil {
- slog.Error("cannot send scold message", "error", err)
- return
- }
-}
-
-func (m *Module) Poke(ctx context.Context, upd *statuspage.StatusUpdate) (*emptypb.Empty, error) {
- return &emptypb.Empty{}, nil
-}