forked from TheBastionBot/Bastion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.ts
195 lines (173 loc) Β· 5.71 KB
/
migrate.ts
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
188
189
190
191
192
193
194
195
/*!
* @author TRACTION (iamtraction)
* @copyright 2022
*/
import { Logger } from "@bastion/tesseract";
import { MongoClient } from "mongodb";
import dotenv from "dotenv";
import Settings from "./utils/settings.js";
// configure dotenv
dotenv.config();
// init
const settings = new Settings();
const client = new MongoClient(settings?.mongoURI);
// commands
const Commands = {
Filters: "filters",
v10: "v10",
};
const v10 = async () => {
await client.connect();
const db = client.db();
// Case
if (await db.collection("cases").findOne()) {
Logger.info("Dropping Case collection...");
await db.collection("cases").drop();
Logger.info("Dropped Case collection.");
}
// Config
if (await db.collection("configs").findOne()) {
Logger.info("Dropping Config collection...");
await db.collection("configs").drop();
Logger.info("Dropped Config collection.");
}
// Giveaway
if (await db.collection("giveaways").findOne()) {
Logger.info("Dropping Giveaway collection...");
await db.collection("giveaways").drop();
Logger.info("Dropped Giveaway collection.");
}
// Guild
if (await db.collection("guilds").findOne()) {
Logger.info("Migrating Guild documents...");
const Guild = db.collection("guilds");
await Guild.updateMany({}, {
$rename: {
moderationLogChannelId: "moderationLogChannel",
serverLogChannelId: "serverLogChannel",
suggestionsChannelId: "suggestionsChannel",
starboardChannelId: "starboardChannel",
reportsChannelId: "reportsChannel",
streamerRoleId: "streamerRole",
verifiedRoleId: "verifiedRole",
},
$unset: {
announcementsChannelId: 1,
chat: 1,
disabled: 1,
disabledCommands: 1,
farewell: 1,
filters: 1,
gambling: 1,
gamification: 1,
greeting: 1,
infractions: 1,
language: 1,
membersOnly: 1,
mentionSpam: 1,
moderationCaseCount: 1,
music: 1,
reactionAnnouncements: 1,
reactionPinning: 1,
referralsChannel: 1,
streamers: 1,
voiceSessions: 1,
},
});
Logger.info("Migrated Guild documents.");
}
// Member
// if (await db.collection("members").findOne()) {}
// Playlist
if (await db.collection("playlists").findOne()) {
Logger.info("Dropping Playlist collection...");
await db.collection("playlists").drop();
Logger.info("Dropped Playlist collection.");
}
// Poll
if (await db.collection("polls").findOne()) {
Logger.info("Dropping Poll collection...");
await db.collection("polls").drop();
Logger.info("Dropped Poll collection.");
}
// ReactionRoleGroup
if (await db.collection("reactionrolegroups").findOne()) {
Logger.info("Dropping ReactionRoleGroup collection...");
await db.collection("reactionrolegroups").drop();
Logger.info("Dropped ReactionRoleGroup collection.");
}
// Role
if (await db.collection("roles").findOne()) {
Logger.info("Migrating Role documents...");
const Role = db.collection("roles");
await Role.updateMany({}, {
$unset: {
autoAssignable: 1,
blacklisted: 1,
disabledCommands: 1,
emoji: 1,
}
});
Logger.info("Migrated Role documents.");
}
// TextChannel
if (await db.collection("textchannels").findOne()) {
Logger.info("Dropping TextChannel collection...");
await db.collection("textchannels").drop();
Logger.info("Dropped TextChannel collection.");
}
// Trigger
if (await db.collection("triggers").findOne()) {
Logger.info("Dropping Trigger collection...");
await db.collection("triggers").drop();
Logger.info("Dropped Trigger collection.");
}
// User
if (await db.collection("users").findOne()) {
Logger.info("Dropping User collection...");
await db.collection("users").drop();
Logger.info("Dropped User collection.");
}
};
const filters = async () => {
await client.connect();
const db = client.db();
// Message Filters
Logger.info("Deleting Filters...");
const Guild = db.collection("guilds");
await Guild.updateMany({}, {
$unset: {
// invite filter
inviteFilter: 1,
inviteFilterWarnings: 1,
inviteFilterExemptions: 1,
// link filter
linkFilter: 1,
linkFilterWarnings: 1,
linkFilterExemptions: 1,
// message filter
messageFilter: 1,
messageFilterWarnings: 1,
messageFilterPatterns: 1,
},
});
Logger.info("Deleted Filters.");
};
const main = () => {
const [ , , command ] = process.argv;
switch (command.toLowerCase()) {
case Commands.Filters: return filters();
case Commands.v10: return v10();
default:
throw new Error("You need to specify a migration command.", {
cause: "None of the valid commands were used: " + Object.values(Commands).join(" / "),
});
}
};
main()
.then(() => Logger.info("Migration completed successfully."))
.catch(e => {
Logger.info("Error when migrating. Join Bastion HQ for support: https://discord.gg/fzx8fkt");
Logger.error(e);
})
.finally(() => client.close());