summaryrefslogtreecommitdiff
path: root/webircgateway/pkg/irc/isupport.go
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-10-24 00:11:55 +0800
committerMistivia <i@mistivia.com>2025-10-24 00:11:55 +0800
commitffa71fb8b2e5521f93d8599279af2b28a0795a66 (patch)
treeacd96fd3e03cb39c8a648c6298b96b9c847e716f /webircgateway/pkg/irc/isupport.go
parent5c71d2a538a93fd4a4fc06cb7941231cc5c0b104 (diff)
add web irc
Diffstat (limited to 'webircgateway/pkg/irc/isupport.go')
-rw-r--r--webircgateway/pkg/irc/isupport.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/webircgateway/pkg/irc/isupport.go b/webircgateway/pkg/irc/isupport.go
new file mode 100644
index 0000000..fdb7bee
--- /dev/null
+++ b/webircgateway/pkg/irc/isupport.go
@@ -0,0 +1,56 @@
+package irc
+
+import (
+ "strings"
+ "sync"
+)
+
+type ISupport struct {
+ Received bool
+ Injected bool
+ Tags map[string]string
+ tokens map[string]string
+ tokensMutex sync.RWMutex
+}
+
+func (m *ISupport) ClearTokens() {
+ m.tokensMutex.Lock()
+ m.tokens = make(map[string]string)
+ m.tokensMutex.Unlock()
+}
+
+func (m *ISupport) AddToken(tokenPair string) {
+ m.tokensMutex.Lock()
+ m.addToken(tokenPair)
+ m.tokensMutex.Unlock()
+}
+
+func (m *ISupport) AddTokens(tokenPairs []string) {
+ m.tokensMutex.Lock()
+ for _, tp := range tokenPairs {
+ m.addToken(tp)
+ }
+ m.tokensMutex.Unlock()
+}
+
+func (m *ISupport) HasToken(key string) (ok bool) {
+ m.tokensMutex.RLock()
+ _, ok = m.tokens[strings.ToUpper(key)]
+ m.tokensMutex.RUnlock()
+ return
+}
+
+func (m *ISupport) GetToken(key string) (val string) {
+ m.tokensMutex.RLock()
+ val = m.tokens[strings.ToUpper(key)]
+ m.tokensMutex.RUnlock()
+ return
+}
+
+func (m *ISupport) addToken(tokenPair string) {
+ kv := strings.Split(tokenPair, "=")
+ if len(kv) == 1 {
+ kv = append(kv, "")
+ }
+ m.tokens[strings.ToUpper(kv[0])] = kv[1]
+}