main.go aktualisiert
All checks were successful
release-tag / release-image (push) Successful in 2m12s
build-binaries / build (, amd64, linux) (push) Has been skipped
build-binaries / build (, arm, 7, linux) (push) Has been skipped
build-binaries / build (, arm64, linux) (push) Has been skipped
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / release (push) Has been skipped
All checks were successful
release-tag / release-image (push) Successful in 2m12s
build-binaries / build (, amd64, linux) (push) Has been skipped
build-binaries / build (, arm, 7, linux) (push) Has been skipped
build-binaries / build (, arm64, linux) (push) Has been skipped
build-binaries / build (.exe, amd64, windows) (push) Has been skipped
build-binaries / release (push) Has been skipped
This commit is contained in:
36
main.go
36
main.go
@@ -174,6 +174,19 @@ func initDB() {
|
||||
addLanguageColumnIfNotExists()
|
||||
ensureLobbyRuleTable()
|
||||
|
||||
_, _ = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS eventlog(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
guild_id TEXT NOT NULL,
|
||||
type TEXT NOT NULL, -- z.B. 'vc_created' | 'vc_deleted' | 'member_moved'
|
||||
channel_id TEXT,
|
||||
user_id TEXT,
|
||||
ts INTEGER NOT NULL, -- unix seconds
|
||||
extra TEXT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_eventlog_guild_ts ON eventlog(guild_id, ts DESC);
|
||||
`)
|
||||
|
||||
}
|
||||
|
||||
// Close DB connection
|
||||
@@ -183,6 +196,21 @@ func closeDB() {
|
||||
}
|
||||
}
|
||||
|
||||
func logEvent(gid, typ, chID, userID string, extra any) {
|
||||
if db == nil {
|
||||
return
|
||||
}
|
||||
var extraJSON string
|
||||
if extra != nil {
|
||||
if b, err := json.Marshal(extra); err == nil {
|
||||
extraJSON = string(b)
|
||||
}
|
||||
}
|
||||
_, _ = db.Exec(`INSERT INTO eventlog(guild_id, type, channel_id, user_id, ts, extra)
|
||||
VALUES(?,?,?,?,?,?)`,
|
||||
gid, typ, chID, userID, time.Now().Unix(), extraJSON)
|
||||
}
|
||||
|
||||
// Laden der Guild-Konfiguration mit Sprache
|
||||
func loadGuildCfgs() error {
|
||||
rows, err := db.Query("SELECT guild_id, lobby_name, category_name, timeout_min, language FROM guild_config")
|
||||
@@ -500,6 +528,10 @@ func createPrivateVCAndMove(
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("VC-Anlage fehlgeschlagen: %w", err)
|
||||
} else {
|
||||
logEvent(guildID, "vc_created", newChan.ID, requesterID, map[string]any{
|
||||
"name": newChan.Name, "timeout_min": timeoutMin,
|
||||
})
|
||||
}
|
||||
|
||||
// optionaler Move
|
||||
@@ -532,6 +564,9 @@ func createPrivateVCAndMove(
|
||||
if moveErr != nil {
|
||||
log.Printf("Move endgültig fehlgeschlagen: %v", moveErr)
|
||||
}
|
||||
if moveErr == nil {
|
||||
logEvent(guildID, "member_moved", newChan.ID, requesterID, nil)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -567,6 +602,7 @@ func watchAndCleanup(s *discordgo.Session, guildID, channelID string, timeout ti
|
||||
if time.Since(lastActive) >= timeout {
|
||||
_, _ = s.ChannelDelete(channelID)
|
||||
log.Println("➖ Deleted channel for guildID: " + guildID + " with ID: " + channelID)
|
||||
logEvent(guildID, "vc_deleted", channelID, "", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user