Skip to content
This repository was archived by the owner on Jun 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ type ClientConfig struct {
// When a user starts a new SAS verification with us, their user ID has to match one of these regexes
// for the verification process to start.
AcceptVerificationFromUsers []string
// The minimum required powerlevel to honour an invite request
MinimumPowerLevel int
}

// A IncomingDecimalSAS contains the decimal SAS as displayed on another device. The SAS consists of three numbers.
Expand Down
33 changes: 27 additions & 6 deletions clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (c *Clients) onBotOptionsEvent(client *mautrix.Client, event *mevt.Event) {
}
}

func (c *Clients) onRoomMemberEvent(client *mautrix.Client, event *mevt.Event) {
func (c *Clients) onRoomMemberEvent(client *BotClient, event *mevt.Event) {
if event.StateKey == nil || *event.StateKey != client.UserID.String() {
return // not our member event
}
Expand All @@ -316,14 +316,35 @@ func (c *Clients) onRoomMemberEvent(client *mautrix.Client, event *mevt.Event) {
})
logger.Print("Accepting invite from user")

content := struct {
inviteContent := struct {
Inviter id.UserID `json:"inviter"`
}{event.Sender}

if _, err := client.JoinRoom(event.RoomID.String(), "", content); err != nil {
if _, err := client.JoinRoom(event.RoomID.String(), "", inviteContent); err != nil {
logger.WithError(err).Print("Failed to join room")
} else {
logger.Print("Joined room")
return
}
logger.Print("Joined room")
var rID = id.RoomID(event.RoomID.String())
var plContent struct {
Users map[string]int `json:"users"`
UsersDefault int
}
if client.config.MinimumPowerLevel == 0 {
Comment thread
jaywink marked this conversation as resolved.
return
}
if err := client.StateEvent(rID, mevt.StatePowerLevels, "", &plContent); err != nil {
logger.WithError(err).Print("Failed to get powerlevels from room")
client.LeaveRoom(rID)
return
}
var pl, userExists = plContent.Users[event.Sender.String()]
if !userExists {
pl = plContent.UsersDefault
}
if pl < client.config.MinimumPowerLevel {
logger.Warningln("User tried to invite the bot without the required PLs, ignoring")
client.LeaveRoom(rID)
}
}
}
Expand Down Expand Up @@ -372,7 +393,7 @@ func (c *Clients) initClient(botClient *BotClient) error {

if config.AutoJoinRooms {
syncer.OnEventType(mevt.StateMember, func(_ mautrix.EventSource, event *mevt.Event) {
c.onRoomMemberEvent(client, event)
c.onRoomMemberEvent(botClient, event)
Comment thread
jaywink marked this conversation as resolved.
})
}

Expand Down
2 changes: 2 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ clients:
AutoJoinRooms: true
DisplayName: "Go-NEB!"
AcceptVerificationFromUsers: [":localhost:8008"]
MinimumPowerLevel: 50

- UserID: "@another_goneb:localhost"
AccessToken: "MDASDASJDIASDJASDAFGFRGER"
Expand All @@ -36,6 +37,7 @@ clients:
AutoJoinRooms: false
DisplayName: "Go-NEB!"
AcceptVerificationFromUsers: ["^@admin:localhost:8008$"]
MinimumPowerLevel: 100

# The list of realms which Go-NEB is aware of.
# Delete or modify this list as appropriate.
Expand Down