]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
Reset score for kicked users.
authorRudolf Polzer <divVerent@gmail.com>
Sat, 2 Nov 2024 12:09:05 +0000 (13:09 +0100)
committerRudolf Polzer <divVerent@gmail.com>
Sat, 2 Nov 2024 12:32:12 +0000 (13:32 +0100)
misc/infrastructure/powerbot/bot.go
misc/infrastructure/powerbot/db.go

index b373c8262fa0b1d465eb994d9c5437c29ec7490e..88e4400a7a4b5dfa312e7e2de3031b26f812f5b9 100644 (file)
@@ -129,6 +129,14 @@ func handleLeave(now time.Time, room id.RoomID, member id.UserID, raw *event.Eve
        setUserStateAt(room, member, now, Active, NotActive)
 }
 
+func handleKicked(now time.Time, room id.RoomID, member id.UserID, raw *event.Event) {
+       log.Printf("[%v] Kicked %v by %v from %v", now, member, raw.Sender, room)
+       roomUsersMu.Lock()
+       delete(roomUsers[room], member)
+       roomUsersMu.Unlock()
+       setUserStateAt(room, member, now, Active, Kicked)
+}
+
 func handlePowerLevels(now time.Time, room id.RoomID, levels *event.PowerLevelsEventContent, raw *event.Event) {
        // log.Printf("[%v] Power levels for %v are %v", now, room, levels)
        levelsCopy := *levels // Looks like mautrix always passes the same pointer here.
@@ -242,8 +250,14 @@ func Run() (err error) {
                switch mem.Membership {
                case event.MembershipJoin:
                        handleJoin(eventTime(evt), evt.RoomID, member, evt)
-               case event.MembershipLeave, event.MembershipBan:
-                       handleLeave(eventTime(evt), evt.RoomID, member, evt)
+               case event.MembershipLeave:
+                       if evt.Sender == member {
+                               handleLeave(eventTime(evt), evt.RoomID, member, evt)
+                       } else {
+                               handleKicked(eventTime(evt), evt.RoomID, member, evt)
+                       }
+               case event.MembershipBan:
+                       handleKicked(eventTime(evt), evt.RoomID, member, evt)
                default: // Ignore.
                }
        })
index d16e11a37f6e761c9ddb2941352676e79457e774..bc37225e5e3761c3bca7b36a7189ce5dfe44b571 100644 (file)
@@ -11,9 +11,10 @@ import (
 type State int
 
 const (
-       NotActive State = iota
-       Idle
-       Active
+       Kicked    State = -1
+       NotActive State = 0
+       Idle      State = 1
+       Active    State = 2
 )
 
 type Score struct {
@@ -114,6 +115,9 @@ func advanceScore(score Score, now time.Time) Score {
                score.Idle += dt
        case Active:
                score.Active += dt
+       case Kicked:
+               score.Idle = 0
+               score.Active = 0
        }
        return score
 }