summaryrefslogtreecommitdiff
path: root/irc/states.go
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2021-04-27 09:45:45 +0200
committerHubert Hirtz <hubert@hirtz.pm>2021-04-27 10:06:38 +0200
commitcede6d5dbe8f4bb98c72b0758703fbe8c572bff6 (patch)
tree2478da7169512e693b69b8c2f6e141bc6cfc051d /irc/states.go
parentdeps: update tcell and runewidth (diff)
Split the "feature" map into specific attributes
Diffstat (limited to '')
-rw-r--r--irc/states.go39
1 files changed, 23 insertions, 16 deletions
diff --git a/irc/states.go b/irc/states.go
index b0e711f..2441d5c 100644
--- a/irc/states.go
+++ b/irc/states.go
@@ -173,7 +173,10 @@ type Session struct {
availableCaps map[string]string
enabledCaps map[string]struct{}
- features map[string]string // server ISUPPORT advertized features.
+
+ // ISUPPORT features
+ casemap func(string) string
+ chantypes string
users map[string]*User // known users.
channels map[string]Channel // joined channels.
@@ -201,7 +204,8 @@ func NewSession(conn net.Conn, params SessionParams) (*Session, error) {
auth: params.Auth,
availableCaps: map[string]string{},
enabledCaps: map[string]struct{}{},
- features: map[string]string{},
+ casemap: CasemapRFC1459,
+ chantypes: "#&",
users: map[string]*User{},
channels: map[string]Channel{},
chBatches: map[string]HistoryEvent{},
@@ -280,19 +284,11 @@ func (s *Session) NickCf() string {
}
func (s *Session) IsChannel(name string) bool {
- chantypes, ok := s.features["CHANTYPES"]
- if !ok {
- chantypes = "#&"
- }
- return strings.IndexAny(name, chantypes) == 0
+ return strings.IndexAny(name, s.chantypes) == 0
}
func (s *Session) Casemap(name string) string {
- if s.features["CASEMAPPING"] == "ascii" {
- return CasemapASCII(name)
- } else {
- return CasemapRFC1459(name)
- }
+ return s.casemap(name)
}
// Users returns the list of all known nicknames.
@@ -1073,10 +1069,21 @@ func (s *Session) updateFeatures(features []string) {
value = kv[1]
}
- if add {
- s.features[key] = value
- } else {
- delete(s.features, key)
+ if !add {
+ // TODO support ISUPPORT negations
+ continue
+ }
+
+ switch key {
+ case "CASEMAPPING":
+ switch value {
+ case "ascii":
+ s.casemap = CasemapASCII
+ default:
+ s.casemap = CasemapRFC1459
+ }
+ case "CHANTYPES":
+ s.chantypes = value
}
}
}