Skip to content

Commit

Permalink
Add send-state <status> command
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Oct 31, 2024
1 parent 7b6be74 commit e1e3de8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/connector/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package connector
import (
"context"
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"strconv"
"strings"
"time"

"maunium.net/go/mautrix/bridge/status"
"maunium.net/go/mautrix/bridgev2/commands"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)

var AllCommands = []commands.CommandHandler{
SendStateCommand,
NewRoomCommand,
GhostsCommand,
MessagesCommand,
Expand All @@ -28,6 +32,42 @@ var DummyHelpsection = commands.HelpSection{
Order: 99,
}

var SendStateCommand = &commands.FullHandler{
Func: func(e *commands.Event) {
if len(e.Args) == 0 {
e.Reply("Missing state argument")
return
}

stateEvent := status.BridgeStateEvent(e.Args[0])
state := status.BridgeState{
StateEvent: stateEvent,
RemoteID: "*",
}

for userID, perm := range e.Bridge.Config.Permissions {
if !perm.Admin {
continue
}
user, err := e.Bridge.GetUserByMXID(context.Background(), id.UserID(userID))
if err != nil {
e.Reply(fmt.Sprintf("Error getting user: %s", err.Error()))
return
}
user.GetDefaultLogin().BridgeState.Send(state)
}

e.Reply("Generated states")
},
Name: "send-state",
Help: commands.HelpMeta{
Description: "Send bridge states",
Args: "[sevent]",
Section: DummyHelpsection,
},
RequiresLogin: true,
}

var NewRoomCommand = &commands.FullHandler{
Func: func(e *commands.Event) {
login := e.User.GetDefaultLogin()
Expand Down

0 comments on commit e1e3de8

Please sign in to comment.