This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
channels.go
84 lines (71 loc) · 1.64 KB
/
channels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"strings"
"sync"
)
const (
colorBlock = "c"
)
var (
channelModes = map[string]string{}
channelModeLock sync.RWMutex
)
func setChannelMode(channel string, mode rune) {
channelModeLock.Lock()
defer channelModeLock.Unlock()
channel = strings.ToLower(channel)
modes, ok := channelModes[channel]
if !ok {
modes = ""
}
for _, knownMode := range modes {
if knownMode == mode {
return
}
}
modes += string(mode)
channelModes[channel] = modes
}
func resetChannelModes(channel string) {
channelModeLock.Lock()
defer channelModeLock.Unlock()
channel = strings.ToLower(channel)
channelModes[channel] = ""
}
func unsetChannelMode(channel string, mode rune) {
channelModeLock.Lock()
defer channelModeLock.Unlock()
channel = strings.ToLower(channel)
modes := channelModes[channel]
index := strings.IndexRune(modes, mode)
if index >= 0 {
modes = modes[0:index] + modes[index+1:]
}
channelModes[channel] = modes
}
func getChannelModes(channel string) string {
channelModeLock.RLock()
defer channelModeLock.RUnlock()
channel = strings.ToLower(channel)
retval, ok := channelModes[channel]
if !ok {
return ""
}
return retval
}
func hasChannelMode(channel string, mode rune) bool {
modes := getChannelModes(channel)
return strings.ContainsRune(modes, mode)
}
func deleteChannelModes(channel string) {
channelModeLock.Lock()
defer channelModeLock.Unlock()
channel = strings.ToLower(channel)
delete(channelModes, channel)
}
func stripIrcFormattingIfChannelBlocksColors(channel string, text string) string {
if strings.Contains(getChannelModes(channel), "c") {
text = stripIrcFormatting(text)
}
return text
}