-
Notifications
You must be signed in to change notification settings - Fork 2
/
structs_guild_settings_welcomer.go
122 lines (107 loc) · 5 KB
/
structs_guild_settings_welcomer.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package backend
import (
"github.com/WelcomerTeam/Welcomer/welcomer-core/database"
utils "github.com/WelcomerTeam/Welcomer/welcomer-utils"
)
type GuildSettingsWelcomer struct {
Text *GuildSettingsWelcomerText `json:"text"`
Images *GuildSettingsWelcomerImages `json:"images"`
DMs *GuildSettingsWelcomerDms `json:"dms"`
Custom *GuildSettingsWelcomerCustom `json:"custom,omitempty"`
}
type GuildSettingsWelcomerText struct {
Channel *string `json:"channel"`
MessageFormat string `json:"message_json"`
ToggleEnabled bool `json:"enabled"`
}
type GuildSettingsWelcomerImages struct {
BackgroundName string `json:"background"`
ColourText string `json:"text_colour"`
ColourTextBorder string `json:"text_colour_border"`
ColourImageBorder string `json:"border_colour"`
ColourProfileBorder string `json:"profile_border_colour"`
ImageAlignment string `json:"image_alignment"`
ImageTheme string `json:"image_theme"`
ImageMessage string `json:"message"`
ImageProfileBorderType string `json:"profile_border_type"`
ToggleEnabled bool `json:"enabled"`
ToggleImageBorder bool `json:"enable_border"`
}
type GuildSettingsWelcomerDms struct {
MessageFormat string `json:"message_json"`
ToggleEnabled bool `json:"enabled"`
ToggleUseTextFormat bool `json:"reuse_message"`
ToggleIncludeImage bool `json:"include_image"`
}
type GuildSettingsWelcomerCustom struct {
CustomBackgroundIDs []string `json:"custom_ids"`
}
func GuildSettingsWelcomerSettingsToPartial(text database.GuildSettingsWelcomerText, images database.GuildSettingsWelcomerImages, dms database.GuildSettingsWelcomerDms, custom *GuildSettingsWelcomerCustom) *GuildSettingsWelcomer {
partial := &GuildSettingsWelcomer{
Text: &GuildSettingsWelcomerText{
ToggleEnabled: text.ToggleEnabled,
Channel: Int64ToStringPointer(text.Channel),
MessageFormat: JSONBToString(text.MessageFormat),
},
Images: &GuildSettingsWelcomerImages{
ToggleEnabled: images.ToggleEnabled,
ToggleImageBorder: images.ToggleImageBorder,
BackgroundName: images.BackgroundName,
ColourText: images.ColourText,
ColourTextBorder: images.ColourTextBorder,
ColourImageBorder: images.ColourImageBorder,
ColourProfileBorder: images.ColourProfileBorder,
ImageAlignment: utils.ImageAlignment(images.ImageAlignment).String(),
ImageTheme: utils.ImageTheme(images.ImageTheme).String(),
ImageMessage: images.ImageMessage,
ImageProfileBorderType: utils.ImageProfileBorderType(images.ImageProfileBorderType).String(),
},
DMs: &GuildSettingsWelcomerDms{
ToggleEnabled: dms.ToggleEnabled,
ToggleUseTextFormat: dms.ToggleUseTextFormat,
ToggleIncludeImage: dms.ToggleIncludeImage,
MessageFormat: JSONBToString(dms.MessageFormat),
},
Custom: custom,
}
return partial
}
func PartialToGuildSettingsWelcomerSettings(guildID int64, guildSettings *GuildSettingsWelcomer) (*database.GuildSettingsWelcomerText, *database.GuildSettingsWelcomerImages, *database.GuildSettingsWelcomerDms) {
return &database.GuildSettingsWelcomerText{
GuildID: guildID,
ToggleEnabled: guildSettings.Text.ToggleEnabled,
Channel: StringPointerToInt64(guildSettings.Text.Channel),
MessageFormat: StringToJSONB(guildSettings.Text.MessageFormat),
}, &database.GuildSettingsWelcomerImages{
GuildID: guildID,
ToggleEnabled: guildSettings.Images.ToggleEnabled,
ToggleImageBorder: guildSettings.Images.ToggleImageBorder,
BackgroundName: guildSettings.Images.BackgroundName,
ColourText: guildSettings.Images.ColourText,
ColourTextBorder: guildSettings.Images.ColourTextBorder,
ColourImageBorder: guildSettings.Images.ColourImageBorder,
ColourProfileBorder: guildSettings.Images.ColourProfileBorder,
ImageAlignment: int32(ParseImageAlignment(guildSettings.Images.ImageAlignment)),
ImageTheme: int32(ParseImageTheme(guildSettings.Images.ImageTheme)),
ImageMessage: guildSettings.Images.ImageMessage,
ImageProfileBorderType: int32(ParseImageProfileBorderType(guildSettings.Images.ImageProfileBorderType)),
}, &database.GuildSettingsWelcomerDms{
GuildID: guildID,
ToggleEnabled: guildSettings.DMs.ToggleEnabled,
ToggleUseTextFormat: guildSettings.DMs.ToggleUseTextFormat,
ToggleIncludeImage: guildSettings.DMs.ToggleIncludeImage,
MessageFormat: StringToJSONB(guildSettings.DMs.MessageFormat),
}
}
func ParseImageAlignment(value string) utils.ImageAlignment {
imageAlignment, _ := utils.ParseImageAlignment(value)
return imageAlignment
}
func ParseImageTheme(value string) utils.ImageTheme {
imageTheme, _ := utils.ParseImageTheme(value)
return imageTheme
}
func ParseImageProfileBorderType(value string) utils.ImageProfileBorderType {
imageProfileBorderType, _ := utils.ParseImageProfileBorderType(value)
return imageProfileBorderType
}