Debian Codegraph @

slackutilsx/slackutilsx.go

raw symbols SCIP
1 // Package slackutilsx is a utility package that doesn't promise API stability.
2 // its for experimental functionality and utilities.
3 package slackutilsxscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/
4
5 import (
6 "stringsscip-go gomod github.com/golang/go/src go1.16 strings/"
7 "unicode/utf8scip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/"
8 )
9
10 // ChannelType the type of channel based on the channelID
11 type ChannelTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/ChannelType# int
12
13 func (t ChannelTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/ChannelType#) Stringscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/ChannelType#String().() string {
14 switch t {
15 case CTypeDMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeDM.:
16 return "Direct"
17 case CTypeGroupscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeGroup.:
18 return "Group"
19 case CTypeChannelscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeChannel.:
20 return "Channel"
21 default:
22 return "Unknown"
23 }
24 }
25
26 const (
27 // CTypeUnknown represents channels we cannot properly detect.
28 CTypeUnknownscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeUnknown. ChannelTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/ChannelType# = iota
29 // CTypeDM is a private channel between two slack users.
30 CTypeDMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeDM.
31 // CTypeGroup is a group channel.
32 CTypeGroupscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeGroup.
33 // CTypeChannel is a public channel.
34 CTypeChannelscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeChannel.
35 )
36
37 // DetectChannelType converts a channelID to a ChannelType.
38 // channelID must not be empty. However, if it is empty, the channel type will default to Unknown.
39 func DetectChannelTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/DetectChannelType().(channelID string) ChannelTypescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/ChannelType# {
40 // intentionally ignore the error and just default to CTypeUnknown
41 switch r, _ := utf8scip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/DecodeRuneInString().(channelID); r {
42 case 'C':
43 return CTypeChannelscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeChannel.
44 case 'G':
45 return CTypeGroupscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeGroup.
46 case 'D':
47 return CTypeDMscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeDM.
48 default:
49 return CTypeUnknownscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/CTypeUnknown.
50 }
51 }
52
53 // initialize replacer only once (if needed)
54 var escapeReplacerscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/escapeReplacer. = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.NewReplacerscip-go gomod github.com/golang/go/src go1.16 strings/NewReplacer().("&", "&amp;", "<", "&lt;", ">", "&gt;")
55
56 // EscapeMessage text
57 func EscapeMessagescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/EscapeMessage().(message string) string {
58 return escapeReplacerscip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/escapeReplacer..Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replacer#Replace().(message)
59 }
60
61 // Retryable errors return true.
62 type Retryablescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/Retryable# interface {
63 Retryablescip-go gomod github.com/slack-go/slack . `github.com/slack-go/slack/slackutilsx`/Retryable#Retryable.() bool
64 }