Merge branch 'stop' into 'main'
add '!pm stop' See merge request etke.cc/postmoogle!7
This commit is contained in:
@@ -18,6 +18,7 @@ var (
|
|||||||
commands = map[string]string{
|
commands = map[string]string{
|
||||||
// special commands
|
// special commands
|
||||||
"help": "Get help",
|
"help": "Get help",
|
||||||
|
"stop": "Disable bridge for that room",
|
||||||
|
|
||||||
// options commands
|
// options commands
|
||||||
"mailbox": "Get or set mailbox of that room",
|
"mailbox": "Get or set mailbox of that room",
|
||||||
@@ -47,6 +48,8 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, command []str
|
|||||||
switch command[0] {
|
switch command[0] {
|
||||||
case "help":
|
case "help":
|
||||||
b.sendHelp(ctx, evt.RoomID)
|
b.sendHelp(ctx, evt.RoomID)
|
||||||
|
case "stop":
|
||||||
|
b.runStop(ctx, evt)
|
||||||
default:
|
default:
|
||||||
b.handleOption(ctx, evt, command)
|
b.handleOption(ctx, evt, command)
|
||||||
}
|
}
|
||||||
@@ -88,6 +91,40 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bot) runStop(ctx context.Context, evt *event.Event) {
|
||||||
|
span := sentry.StartSpan(ctx, "http.server", sentry.TransactionName("runStop"))
|
||||||
|
defer span.Finish()
|
||||||
|
|
||||||
|
cfg, err := b.getSettings(span.Context(), evt.RoomID)
|
||||||
|
if err != nil {
|
||||||
|
b.Error(span.Context(), evt.RoomID, "failed to retrieve settings: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !cfg.Allowed(b.noowner, evt.Sender) {
|
||||||
|
b.Notice(span.Context(), evt.RoomID, "you don't have permission to do that")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mailbox := cfg.Get("mailbox")
|
||||||
|
if mailbox == "" {
|
||||||
|
b.Notice(span.Context(), evt.RoomID, "that room is not configured yet")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.roomsmu.Lock()
|
||||||
|
delete(b.rooms, mailbox)
|
||||||
|
b.roomsmu.Unlock()
|
||||||
|
|
||||||
|
err = b.setSettings(span.Context(), evt.RoomID, settings{})
|
||||||
|
if err != nil {
|
||||||
|
b.Error(span.Context(), evt.RoomID, "cannot update settings: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Notice(span.Context(), evt.RoomID, "mailbox has been disabled")
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Bot) handleOption(ctx context.Context, evt *event.Event, command []string) {
|
func (b *Bot) handleOption(ctx context.Context, evt *event.Event, command []string) {
|
||||||
if len(command) == 1 {
|
if len(command) == 1 {
|
||||||
b.getOption(ctx, evt, command[0])
|
b.getOption(ctx, evt, command[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user