More initialization order fixes (vol 2)
This commit is contained in:
parent
22316eb714
commit
72637fe1b3
27 changed files with 97 additions and 44 deletions
|
@ -58,13 +58,17 @@ export const CensorPlugin = zeppelinGuildPlugin<CensorPluginType>()({
|
|||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.serverLogs = new GuildLogs(guild.id);
|
||||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
|
||||
state.regexRunner = getRegExpRunner(`guild-${pluginData.guild.id}`);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
|
|
|
@ -14,9 +14,5 @@ export const ChannelArchiverPlugin = zeppelinGuildPlugin<ChannelArchiverPluginTy
|
|||
// prettier-ignore
|
||||
commands: [
|
||||
ArchiveChannelCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
},
|
||||
]
|
||||
});
|
||||
|
|
|
@ -31,7 +31,7 @@ export const CompanionChannelsPlugin = zeppelinGuildPlugin<CompanionChannelsPlug
|
|||
|
||||
events: [VoiceChannelJoinEvt, VoiceChannelSwitchEvt, VoiceChannelLeaveEvt],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.errorCooldownManager = new CooldownManager();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -146,7 +146,7 @@ export const CountersPlugin = zeppelinGuildPlugin<CountersPluginType>()({
|
|||
ResetAllCounterValuesCmd,
|
||||
],
|
||||
|
||||
async afterLoad(pluginData) {
|
||||
async beforeLoad(pluginData) {
|
||||
pluginData.state.counters = new GuildCounters(pluginData.guild.id);
|
||||
pluginData.state.events = new EventEmitter();
|
||||
pluginData.state.counterTriggersByCounterId = new Map();
|
||||
|
@ -190,6 +190,10 @@ export const CountersPlugin = zeppelinGuildPlugin<CountersPluginType>()({
|
|||
|
||||
// Mark old/unused triggers to be deleted later
|
||||
await pluginData.state.counters.markUnusedTriggersToBeDeleted(activeTriggerIds);
|
||||
},
|
||||
|
||||
async afterLoad(pluginData) {
|
||||
const config = pluginData.config.get();
|
||||
|
||||
// Start decay timers
|
||||
pluginData.state.decayTimers = [];
|
||||
|
|
|
@ -35,9 +35,11 @@ export const GuildAccessMonitorPlugin = zeppelinGlobalPlugin<GuildAccessMonitorP
|
|||
}),
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.allowedGuilds = new AllowedGuilds();
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
for (const guild of pluginData.client.guilds.values()) {
|
||||
checkGuild(pluginData, guild);
|
||||
}
|
||||
|
|
|
@ -10,10 +10,12 @@ export const GuildConfigReloaderPlugin = zeppelinGlobalPlugin<GuildConfigReloade
|
|||
|
||||
configSchema: t.type({}),
|
||||
|
||||
async afterLoad(pluginData) {
|
||||
async beforeLoad(pluginData) {
|
||||
pluginData.state.guildConfigs = new Configs();
|
||||
pluginData.state.highestConfigId = await pluginData.state.guildConfigs.getHighestId();
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
reloadChangedGuilds(pluginData);
|
||||
},
|
||||
|
||||
|
|
|
@ -11,13 +11,17 @@ export const GuildInfoSaverPlugin = zeppelinGuildPlugin<GuildInfoSaverPluginType
|
|||
|
||||
configSchema: t.type({}),
|
||||
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.allowedGuilds = new AllowedGuilds();
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.allowedGuilds = new AllowedGuilds();
|
||||
|
||||
updateGuildInfo(pluginData);
|
||||
state.updateInterval = setInterval(() => updateGuildInfo(pluginData), 60 * MINUTES);
|
||||
pluginData.state.updateInterval = setInterval(() => updateGuildInfo(pluginData), 60 * MINUTES);
|
||||
},
|
||||
|
||||
beforeUnload(pluginData) {
|
||||
clearInterval(pluginData.state.updateInterval);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -59,14 +59,16 @@ export const LocateUserPlugin = zeppelinGuildPlugin<LocateUserPluginType>()({
|
|||
GuildBanRemoveAlertsEvt
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.alerts = GuildVCAlerts.getGuildInstance(guild.id);
|
||||
state.outdatedAlertsTimeout = null;
|
||||
state.usersWithAlerts = [];
|
||||
state.unloaded = false;
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
outdatedAlertsLoop(pluginData);
|
||||
fillActiveAlertsList(pluginData);
|
||||
},
|
||||
|
|
|
@ -85,7 +85,7 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
},
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.guildLogs = new GuildLogs(guild.id);
|
||||
|
@ -93,11 +93,17 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
state.archives = GuildArchives.getGuildInstance(guild.id);
|
||||
state.cases = GuildCases.getGuildInstance(guild.id);
|
||||
|
||||
state.batches = new Map();
|
||||
|
||||
state.regexRunner = getRegExpRunner(`guild-${pluginData.guild.id}`);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.logListener = ({ type, data }) => log(pluginData, type, data);
|
||||
state.guildLogs.on("log", state.logListener);
|
||||
|
||||
state.batches = new Map();
|
||||
|
||||
state.onMessageDeleteFn = msg => onMessageDelete(pluginData, msg);
|
||||
state.savedMessages.events.on("delete", state.onMessageDeleteFn);
|
||||
|
||||
|
@ -107,7 +113,6 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
|
|||
state.onMessageUpdateFn = (newMsg, oldMsg) => onMessageUpdate(pluginData, newMsg, oldMsg);
|
||||
state.savedMessages.events.on("update", state.onMessageUpdateFn);
|
||||
|
||||
state.regexRunner = getRegExpRunner(`guild-${pluginData.guild.id}`);
|
||||
state.regexRunnerRepeatedTimeoutListener = (regexSource, timeoutMs, failedTimes) => {
|
||||
logger.warn(`Disabled heavy regex temporarily: ${regexSource}`);
|
||||
log(pluginData, LogType.BOT_ALERT, {
|
||||
|
|
|
@ -41,7 +41,7 @@ export const MessageSaverPlugin = zeppelinGuildPlugin<MessageSaverPluginType>()(
|
|||
MessageDeleteBulkEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
},
|
||||
|
|
|
@ -188,7 +188,7 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
|
|||
},
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.mutes = GuildMutes.getGuildInstance(guild.id);
|
||||
|
@ -204,7 +204,9 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
|
|||
state.massbanQueue = new Queue(15 * MINUTES);
|
||||
|
||||
state.events = new EventEmitter();
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
outdatedTempbansLoop(pluginData);
|
||||
},
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ export const NameHistoryPlugin = zeppelinGuildPlugin<NameHistoryPluginType>()({
|
|||
MessageCreateEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.nicknameHistory = GuildNicknameHistory.getGuildInstance(guild.id);
|
||||
|
|
|
@ -37,7 +37,7 @@ export const PersistPlugin = zeppelinGuildPlugin<PersistPluginType>()({
|
|||
LoadDataEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.persistedData = GuildPersistedData.getGuildInstance(guild.id);
|
||||
|
|
|
@ -42,7 +42,7 @@ export const PingableRolesPlugin = zeppelinGuildPlugin<PingableRolesPluginType>(
|
|||
MessageCreateDisablePingableEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.pingableRoles = GuildPingableRoles.getGuildInstance(guild.id);
|
||||
|
|
|
@ -50,13 +50,15 @@ export const PostPlugin = zeppelinGuildPlugin<PostPluginType>()({
|
|||
ScheduledPostsDeleteCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
state.scheduledPosts = GuildScheduledPosts.getGuildInstance(guild.id);
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
scheduledPostLoop(pluginData);
|
||||
},
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ export const ReactionRolesPlugin = zeppelinGuildPlugin<ReactionRolesPluginType>(
|
|||
AddReactionRoleEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.reactionRoles = GuildReactionRoles.getGuildInstance(guild.id);
|
||||
|
@ -63,7 +63,9 @@ export const ReactionRolesPlugin = zeppelinGuildPlugin<ReactionRolesPluginType>(
|
|||
state.roleChangeQueue = new Queue();
|
||||
state.pendingRoleChanges = new Map();
|
||||
state.pendingRefreshes = new Set();
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
let autoRefreshInterval = pluginData.config.get().auto_refresh_interval;
|
||||
if (autoRefreshInterval != null) {
|
||||
autoRefreshInterval = Math.max(MIN_AUTO_REFRESH, autoRefreshInterval);
|
||||
|
|
|
@ -40,7 +40,7 @@ export const RemindersPlugin = zeppelinGuildPlugin<RemindersPluginType>()({
|
|||
RemindersDeleteCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.reminders = GuildReminders.getGuildInstance(guild.id);
|
||||
|
@ -48,6 +48,9 @@ export const RemindersPlugin = zeppelinGuildPlugin<RemindersPluginType>()({
|
|||
state.unloaded = false;
|
||||
|
||||
state.postRemindersTimeout = null;
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
postDueRemindersLoop(pluginData);
|
||||
},
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ export const RolesPlugin = zeppelinGuildPlugin<RolesPluginType>()({
|
|||
MassRemoveRoleCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
|
|
|
@ -94,7 +94,7 @@ export const SelfGrantableRolesPlugin = zeppelinGuildPlugin<SelfGrantableRolesPl
|
|||
RoleAddCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.cooldowns = new CooldownManager();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -55,12 +55,17 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
SlowmodeSetCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.slowmodes = GuildSlowmodes.getGuildInstance(guild.id);
|
||||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state } = pluginData;
|
||||
|
||||
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
|
@ -69,5 +74,6 @@ export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|||
|
||||
beforeUnload(pluginData) {
|
||||
pluginData.state.savedMessages.events.off("create", pluginData.state.onMessageCreateFn);
|
||||
clearInterval(pluginData.state.clearInterval);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@ export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()({
|
|||
SpamVoiceSwitchEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
|
@ -73,16 +73,21 @@ export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()({
|
|||
state.mutes = GuildMutes.getGuildInstance(guild.id);
|
||||
|
||||
state.recentActions = [];
|
||||
state.expiryInterval = setInterval(() => clearOldRecentActions(pluginData), 1000 * 60);
|
||||
state.lastHandledMsgIds = new Map();
|
||||
|
||||
state.spamDetectionQueue = Promise.resolve();
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state } = pluginData;
|
||||
|
||||
state.expiryInterval = setInterval(() => clearOldRecentActions(pluginData), 1000 * 60);
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
},
|
||||
|
||||
beforeUnload(pluginData) {
|
||||
pluginData.state.savedMessages.events.off("create", pluginData.state.onMessageCreateFn);
|
||||
clearInterval(pluginData.state.expiryInterval);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -146,12 +146,16 @@ export const StarboardPlugin = zeppelinGuildPlugin<StarboardPluginType>()({
|
|||
StarboardReactionRemoveAllEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
state.starboardMessages = GuildStarboardMessages.getGuildInstance(guild.id);
|
||||
state.starboardReactions = GuildStarboardReactions.getGuildInstance(guild.id);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state } = pluginData;
|
||||
|
||||
state.onMessageDeleteFn = msg => onMessageDelete(pluginData, msg);
|
||||
state.savedMessages.events.on("delete", state.onMessageDeleteFn);
|
||||
|
|
|
@ -97,7 +97,7 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()({
|
|||
return options;
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.archives = GuildArchives.getGuildInstance(guild.id);
|
||||
|
@ -105,6 +105,12 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()({
|
|||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
|
||||
state.tagFunctions = {};
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
||||
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ export const TimeAndDatePlugin = zeppelinGuildPlugin<TimeAndDatePluginType>()({
|
|||
getDateFormat: mapToPublicFn(getDateFormat),
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.memberTimezones = GuildMemberTimezones.getGuildInstance(pluginData.guild.id);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ export const UsernameSaverPlugin = zeppelinGuildPlugin<UsernameSaverPluginType>(
|
|||
VoiceChannelJoinUpdateUsernameEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.usernameHistory = new UsernameHistory();
|
||||
|
|
|
@ -148,7 +148,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
|
|||
EmojiInfoCmd,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
|
@ -161,11 +161,6 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
|
|||
|
||||
state.lastReload = Date.now();
|
||||
|
||||
if (activeReloads.has(guild.id)) {
|
||||
sendSuccessMessage(pluginData, activeReloads.get(guild.id)!, "Reloaded!");
|
||||
activeReloads.delete(guild.id);
|
||||
}
|
||||
|
||||
// FIXME: Temp fix for role change detection for specific servers, load all guild members in the background on bot start
|
||||
const roleChangeDetectionFixServers = [
|
||||
"786212572285763605",
|
||||
|
@ -182,6 +177,15 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
|
|||
}
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const { guild } = pluginData;
|
||||
|
||||
if (activeReloads.has(guild.id)) {
|
||||
sendSuccessMessage(pluginData, activeReloads.get(guild.id)!, "Reloaded!");
|
||||
activeReloads.delete(guild.id);
|
||||
}
|
||||
},
|
||||
|
||||
beforeUnload(pluginData) {
|
||||
discardRegExpRunner(`guild-${pluginData.guild.id}`);
|
||||
},
|
||||
|
|
|
@ -27,7 +27,7 @@ export const WelcomeMessagePlugin = zeppelinGuildPlugin<WelcomeMessagePluginType
|
|||
SendWelcomeMessageEvt,
|
||||
],
|
||||
|
||||
afterLoad(pluginData) {
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
|
|
Loading…
Add table
Reference in a new issue