Fix bad channel management for topic changes.

master
Icedream 2018-06-15 00:03:42 +02:00
parent ded03116cc
commit 081d354bab
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
2 changed files with 24 additions and 1 deletions

10
main.go
View File

@ -167,7 +167,7 @@ func main() {
} }
} }
for _, target := range channels { for _, target := range m.GetChannels() {
oldTopic := m.GetTopic(target) oldTopic := m.GetTopic(target)
oldTopicParts := strings.Split(oldTopic, "|") oldTopicParts := strings.Split(oldTopic, "|")
@ -350,6 +350,14 @@ func main() {
default: default:
} }
}) })
conn.AddCallback("PART", func(e *irc.Event) {
// Is this PART not about us?
if !strings.EqualFold(e.Nick, conn.GetNick()) {
return
}
m.DeleteTopic(e.Arguments[0])
})
conn.AddCallback("INVITE", func(e *irc.Event) { conn.AddCallback("INVITE", func(e *irc.Event) {
// Allow invites? // Allow invites?
if !allowInvite { if !allowInvite {

View File

@ -6,6 +6,14 @@ func (m *Manager) initTopic() {
m.topicMap = map[string]string{} m.topicMap = map[string]string{}
} }
func (m *Manager) GetChannels() (channels []string) {
channels = []string{}
for name, _ := range m.topicMap {
channels = append(channels, name)
}
return
}
func (m *Manager) GetTopic(channel string) (retval string) { func (m *Manager) GetTopic(channel string) (retval string) {
channel = strings.ToLower(channel) channel = strings.ToLower(channel)
m.topicStateLock.RLock() m.topicStateLock.RLock()
@ -20,3 +28,10 @@ func (m *Manager) SaveTopic(channel string, topic string) {
defer m.topicStateLock.Unlock() defer m.topicStateLock.Unlock()
m.topicMap[channel] = topic m.topicMap[channel] = topic
} }
func (m *Manager) DeleteTopic(channel string) {
channel = strings.ToLower(channel)
m.topicStateLock.Lock()
defer m.topicStateLock.Unlock()
delete(m.topicMap, channel)
}