diff --git a/main.go b/main.go index b1fd707..70b01ca 100644 --- a/main.go +++ b/main.go @@ -167,7 +167,7 @@ func main() { } } - for _, target := range channels { + for _, target := range m.GetChannels() { oldTopic := m.GetTopic(target) oldTopicParts := strings.Split(oldTopic, "|") @@ -350,6 +350,14 @@ func main() { 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) { // Allow invites? if !allowInvite { diff --git a/manager/topic.go b/manager/topic.go index 1851028..5ce0b1d 100644 --- a/manager/topic.go +++ b/manager/topic.go @@ -6,6 +6,14 @@ func (m *Manager) initTopic() { 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) { channel = strings.ToLower(channel) m.topicStateLock.RLock() @@ -20,3 +28,10 @@ func (m *Manager) SaveTopic(channel string, topic string) { defer m.topicStateLock.Unlock() 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) +}