forked from KaylorBen/nixcord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.nix
187 lines (178 loc) · 4.41 KB
/
lib.nix
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{ lib, parseRules, ... }:
let
inherit (lib)
attrsets
strings
;
inherit (attrsets)
mapAttrs'
nameValuePair
;
upperNames = [
# these are option names to become UPPER_SNAKE_CASE
"webhook"
"owner"
"administrator"
"moderatorStaff"
"moderator"
"voiceModerator"
"chatModerator"
"skipHostUpdate"
"dangerousEnableDevtoolsOnlyEnableIfYouKnowWhatYoureDoing"
"minWidth"
"minHeight"
"isMaximized"
"isMinimized"
"windowBounds"
"openOnStartup"
"minimizeToTray"
] ++ parseRules.upperNames;
lowerPluginTitles = [
# these are the only plugins with lowercase names in json
"iLoveSpam"
"petpet"
] ++ parseRules.lowerPluginTitles;
# this is since many json options in Vencord are just int values with no description
# ALL OF THESE HAVE TO BE UNIQUE!!!
zeroOptions = [
# options which evaluate to int 0
"randomCharacters"
"never"
"playing"
"none"
"everything"
"all"
"recentlyActive"
"normal"
"highestRole"
"mostRecent"
"disabled"
"compact"
"plain"
"whitelist"
] ++ parseRules.fakeEnums.zero;
oneOptions = [
# options which evaluate to int 1
"consistent"
"always"
"streaming"
"discordUptime"
"titles"
"only@Mentions"
"list"
"datePosted"
"better"
"lowestRole"
"custom"
"preferDiscord"
"enabled"
"onlyServerCount"
"cozy"
"muted"
"animatedDots"
"blacklist"
] ++ parseRules.fakeEnums.one;
twoOptions = [
# options which evaluate to int 2
"timestamp"
"moreThanOne"
"listening"
"currentTime"
"thumbnails"
"nothing"
"gallery"
"projectX"
"followNoReplyMention"
"onlyFriendCount"
"roomy"
"avatars"
] ++ parseRules.fakeEnums.two;
threeOptions = [
# options which evaluate to int 3
"watching"
"customTime"
"serverDefault"
"both" # This references 2 options that both = 3 in JSON
] ++ parseRules.fakeEnums.three;
fourOptions = [
"competing"
] ++ parseRules.fakeEnums.four;
isLowerCase = s: strings.toLower s == s;
unNixify =
nixName:
(strings.toUpper (
strings.concatStrings (
builtins.map (char: if (isLowerCase char) then char else "_" + char) (
strings.stringToCharacters nixName
)
)
));
isLowerCamel = string: (isLowerCase (builtins.substring 0 1 string));
toUpper =
string:
(strings.concatStrings [
(strings.toUpper (builtins.substring 0 1 string))
(builtins.substring 1 (builtins.stringLength string) string)
]);
mkVencordCfg =
cfg:
let
recurse = mapAttrs' (
name: value:
nameValuePair
(
# probably some kind of map function is better than this
if name == "enable" then
"enabled"
else if name == "tagSettings" then
"tagSettings"
# the only name that = attrset not in upperNames
else if name == "nsfwGateBypass" then
"NSFWGateBypass"
# acronym needs special rule
else if name == "banger" then
"BANger"
else if name == "useQuickCss" then
"useQuickCSS"
else if name == "webRichPresence" then
"WebRichPresence (arRPC)"
else if builtins.elem name upperNames then
unNixify name
else if builtins.elem name lowerPluginTitles then
name
else if builtins.isAttrs value && builtins.hasAttr "enable" value && isLowerCamel name then
toUpper name
else
name
)
(
if builtins.isAttrs value then
recurse value
# recurse into subsequent attrs
else if builtins.elem value zeroOptions then
0
# no concievable way to generalize
else if builtins.elem value oneOptions then
1
# these without an upstream
else if builtins.elem value twoOptions then
2
# change at Vencord since
else if builtins.elem value threeOptions then
3
# these settings enums are
else if builtins.elem value fourOptions then
4
# completely arbitrary
else
value
)
);
in
recurse cfg;
in
{
inherit
mkVencordCfg
;
}