feat: clean channel from other messages on startup
This commit is contained in:
parent
13e1ee2183
commit
31b7637764
1 changed files with 25 additions and 0 deletions
25
monitor.go
25
monitor.go
|
|
@ -37,6 +37,8 @@ func (m *StatusMonitor) Start() {
|
|||
|
||||
m.updateStatus()
|
||||
|
||||
m.cleanChannel()
|
||||
|
||||
ticker := time.NewTicker(m.interval)
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
|
|
@ -45,6 +47,29 @@ func (m *StatusMonitor) Start() {
|
|||
}()
|
||||
}
|
||||
|
||||
func (m *StatusMonitor) cleanChannel() {
|
||||
msgs, err := m.session.ChannelMessages(m.channelID, 100, "", "", "")
|
||||
if err != nil {
|
||||
log.Printf("Error fetching messages for cleanup: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var toDelete []string
|
||||
for _, msg := range msgs {
|
||||
if msg.Author.ID != m.session.State.User.ID {
|
||||
toDelete = append(toDelete, msg.ID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(toDelete) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if err := m.session.ChannelMessagesBulkDelete(m.channelID, toDelete); err != nil {
|
||||
log.Printf("Error bulk deleting messages: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *StatusMonitor) findExistingMessage() {
|
||||
msgs, err := m.session.ChannelMessages(m.channelID, 50, "", "", "")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue