aboutsummaryrefslogtreecommitdiff
path: root/cmd/mimi/modules
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-04-05 11:52:33 -0400
committerXe Iaso <me@xeiaso.net>2024-04-05 11:52:49 -0400
commit91b2cdc4f2747f730a493b23f2362701eaefa066 (patch)
treeb190ee2088c7f9122b1594112dc5ed93cd54a644 /cmd/mimi/modules
parent0b484d1f236dadde16d84563103e1ba53879e0ee (diff)
downloadx-91b2cdc4f2747f730a493b23f2362701eaefa066.tar.xz
x-91b2cdc4f2747f730a493b23f2362701eaefa066.zip
proto: add mi types
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/mimi/modules')
-rw-r--r--cmd/mimi/modules/discord/flyio/flyio.go11
-rw-r--r--cmd/mimi/modules/discord/flyio/statuspage.go75
2 files changed, 83 insertions, 3 deletions
diff --git a/cmd/mimi/modules/discord/flyio/flyio.go b/cmd/mimi/modules/discord/flyio/flyio.go
index e9a8d23..98fd837 100644
--- a/cmd/mimi/modules/discord/flyio/flyio.go
+++ b/cmd/mimi/modules/discord/flyio/flyio.go
@@ -15,7 +15,9 @@ import (
)
var (
- flyDiscordGuild = flag.String("fly-discord-guild", "1194719413732130866", "fly discord guild ID")
+ flyDiscordGuild = flag.String("fly-discord-guild", "1194719413732130866", "fly discord guild ID")
+ flyDiscordXeID = flag.String("fly-discord-xe", "72838115944828928", "fly discord xe ID")
+ flyDiscordTeamID = flag.String("fly-discord-team", "1197660035212394657", "fly discord team ID")
)
func p[T any](t T) *T {
@@ -24,7 +26,7 @@ func p[T any](t T) *T {
func mentionsXe(m *discordgo.MessageCreate) bool {
for _, u := range m.Mentions {
- if u.ID == "72838115944828928" {
+ if u.ID == *flyDiscordXeID {
return true
}
}
@@ -34,7 +36,7 @@ func mentionsXe(m *discordgo.MessageCreate) bool {
func mentionsTeam(m *discordgo.MessageCreate) bool {
for _, u := range m.MentionRoles {
- if u == "1197660035212394657" {
+ if u == *flyDiscordTeamID {
return true
}
}
@@ -45,6 +47,7 @@ func mentionsTeam(m *discordgo.MessageCreate) bool {
type Module struct {
ola *ollama.Client
model string
+ sess *discordgo.Session
}
func New() *Module {
@@ -92,6 +95,8 @@ func (m *Module) judgeIfAboutFlyIO(ctx context.Context, msg string) (bool, error
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) {
diff --git a/cmd/mimi/modules/discord/flyio/statuspage.go b/cmd/mimi/modules/discord/flyio/statuspage.go
new file mode 100644
index 0000000..f238902
--- /dev/null
+++ b/cmd/mimi/modules/discord/flyio/statuspage.go
@@ -0,0 +1,75 @@
+package flyio
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "log/slog"
+ "net/http"
+ "strings"
+
+ "github.com/bwmarrin/discordgo"
+ "google.golang.org/protobuf/types/known/emptypb"
+ "within.website/x/proto/mimi/statuspage"
+)
+
+var (
+ statusChannelID = flag.String("fly-discord-status-channel", "1194719777625751573", "fly discord status channel ID")
+)
+
+func (m *Module) RegisterHTTP(mux *http.ServeMux) {
+ mux.Handle(statuspage.UpdatePathPrefix, statuspage.NewUpdateServer(&UpdateService{Module: m}))
+}
+
+type UpdateService struct {
+ *Module
+}
+
+func (u *UpdateService) Poke(ctx context.Context, sp *statuspage.StatusUpdate) (*emptypb.Empty, error) {
+ go u.UpdateStatus(context.Background(), sp)
+
+ return &emptypb.Empty{}, nil
+}
+
+func (u *UpdateService) UpdateStatus(ctx context.Context, sp *statuspage.StatusUpdate) {
+ if sp.GetIncident() != nil {
+ u.UpdateIncident(ctx, sp.GetIncident())
+ return
+ }
+
+ u.UpdateComponent(ctx, sp)
+}
+
+func (u *UpdateService) UpdateIncident(ctx context.Context, incident *statuspage.Incident) {
+ var sb strings.Builder
+
+ fmt.Fprintf(&sb, "# %s\nimpact: %s\n", incident.GetName(), incident.GetImpact())
+ fmt.Fprintf(&sb, "Follow the incident at %s\n", incident.GetShortlink())
+ fmt.Fprintf(&sb, "Status: %s\n", incident.GetStatus())
+ fmt.Fprintf(&sb, "Latest update:\n")
+ fmt.Fprintf(&sb, "At %s: \n%s\n\n", incident.GetIncidentUpdates()[0].GetCreatedAt(), incident.GetIncidentUpdates()[0].GetBody())
+
+ if _, err := u.sess.ChannelMessageSendEmbed(*statusChannelID, &discordgo.MessageEmbed{
+ URL: incident.GetShortlink(),
+ Title: fmt.Sprintf("Incident %s: %s", incident.GetId(), incident.GetName()),
+ Description: sb.String(),
+ }, discordgo.WithContext(ctx)); err != nil {
+ slog.Error("failed to send incident update", "err", err, "incident", incident)
+ return
+ }
+}
+
+func (u *UpdateService) UpdateComponent(ctx context.Context, sp *statuspage.StatusUpdate) {
+ var sb strings.Builder
+
+ fmt.Fprintf(&sb, "# %s\nstatus: %s\n", sp.GetComponent().GetName(), sp.GetComponent().GetStatus())
+
+ if _, err := u.sess.ChannelMessageSendEmbed(*statusChannelID, &discordgo.MessageEmbed{
+ URL: "https://status.flyio.net/",
+ Title: fmt.Sprintf("Component %s: %s", sp.GetComponent().GetId(), sp.GetComponent().GetName()),
+ Description: sb.String(),
+ }); err != nil {
+ slog.Error("failed to send component update", "err", err, "component", sp.GetComponent())
+ return
+ }
+}