MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / extractDiscordConfig

Function extractDiscordConfig

agent/app/service/agents_channels.go:902–950  ·  view source on GitHub ↗
(conf map[string]interface{})

Source from the content-addressed store, hash-verified

900}
901
902func extractDiscordConfig(conf map[string]interface{}) dto.AgentDiscordConfig {
903 result := dto.AgentDiscordConfig{Enabled: true, DmPolicy: "pairing", AllowFrom: []string{}, RequireMention: false, GroupPolicy: "open"}
904 discord := getChannelConfig(conf, "discord")
905 if len(discord) == 0 {
906 return result
907 }
908 if enabled, ok := discord["enabled"].(bool); ok {
909 result.Enabled = enabled
910 }
911 if dmPolicy := extractStringValue(discord["dmPolicy"]); dmPolicy != "" {
912 result.DmPolicy = dmPolicy
913 } else if dm := childMap(discord, "dm"); dm != nil {
914 if policy := extractStringValue(dm["policy"]); policy != "" {
915 result.DmPolicy = policy
916 }
917 }
918 if groupPolicy := extractStringValue(discord["groupPolicy"]); groupPolicy != "" {
919 result.GroupPolicy = groupPolicy
920 }
921 result.RequireMention = result.GroupPolicy == "allowlist"
922 result.AllowFrom = extractStringList(discord["allowFrom"])
923 result.Proxy = extractStringValue(discord["proxy"])
924 accounts := childMap(discord, "accounts")
925 if len(accounts) == 0 {
926 token := extractStringValue(discord["token"])
927 if token != "" {
928 accounts["default"] = map[string]interface{}{
929 "enabled": extractBoolValue(discord["enabled"], true),
930 "token": token,
931 }
932 }
933 }
934 bots := make([]dto.AgentDiscordBot, 0, len(accounts))
935 for _, accountID := range sortedChildKeys(accounts) {
936 account := childMap(accounts, accountID)
937 bots = append(bots, dto.AgentDiscordBot{
938 AgentChannelBotBase: dto.AgentChannelBotBase{
939 AccountID: accountID,
940 Name: extractDisplayName(account, accountID, accountID),
941 Enabled: extractBoolValue(account["enabled"], true),
942 },
943 Token: extractStringValue(account["token"]),
944 })
945 }
946 result.DefaultAccount = normalizeDefaultAccount(extractStringValue(discord["defaultAccount"]), getDiscordBotAccountIDs(bots))
947 setDiscordDefaultFlags(bots, result.DefaultAccount)
948 result.Bots = bots
949 return result
950}
951
952func setDiscordConfig(conf map[string]interface{}, config dto.AgentDiscordConfig) {
953 channels := ensureChildMap(conf, "channels")

Callers 2

GetDiscordConfigMethod · 0.85

Calls 10

getChannelConfigFunction · 0.85
extractStringValueFunction · 0.85
childMapFunction · 0.85
extractStringListFunction · 0.85
extractBoolValueFunction · 0.85
sortedChildKeysFunction · 0.85
extractDisplayNameFunction · 0.85
normalizeDefaultAccountFunction · 0.85
getDiscordBotAccountIDsFunction · 0.85
setDiscordDefaultFlagsFunction · 0.85

Tested by

no test coverage detected