Skip to content

Commit

Permalink
gravefully recover calendar, disable delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mchangrh committed Dec 21, 2021
1 parent accd2bf commit c88a4fb
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions handlers/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ function killUpdateTimer (guildID, reason = "none") {
console.error(message);
}

/**
* Recreate calendar instead of killing
* @param {String} guildID
* @param {String} reason
*/
function recreateCalendar (guildID, channel, reason = "none") {
const message = `recreated ${guildID} | ${reason}`;
const guild = new guilds.Guild(guildID);
discordLog(message);
console.error(message);
// create calendar
getEvents(guild, channel);
postCalendar(guild, channel);
}

/**
* Cleans messages from the channel
* @param {Snowflake} channel - channel to delete the messages in
Expand Down Expand Up @@ -184,7 +199,7 @@ function getEventsErrorHandler(err, guild, channel) {
} else { discordLog(`getEvents error in guild: ${guild.id} : ${err}`);
}
channel.send(i18n.t("timerkilled", { lng: guild.lng }));
killUpdateTimer(guild.id, "getEvents");
recreateCalendar(guild.id, channel, "getEvents");
}

/**
Expand Down Expand Up @@ -334,7 +349,8 @@ function generateCalendarCodeblock(guild) {
const eventTitle = (event.summary) ? helpers.trimEventName(event.summary, guildSettings.trim) : " ";
const duration = durationString(event, guild);
const tempString = {[duration]: eventTitle};
sendString += (guildSettings.eventtime === "1" ? columnify(tempString, options) + "\n" : eventTitle + "\n");
const lineString = (guildSettings.seperateheader === "1" ? duration + "\n" + eventTitle : columnify(tempString, options));
sendString += (guildSettings.eventtime === "1" ? lineString + "\n" : eventTitle + "\n");
});
sendString += "```";
}
Expand Down Expand Up @@ -471,7 +487,7 @@ function generateCalendar(guild, channel) {
function startUpdateTimer(guildID, channelid) {
if (updaterList.exists(guildID)) {
log(`startUpdateTimer | ${guildID} | updater exists exists`);
return discordLog(`timer not started in guild: ${guildID}`);
return discordLog(`timer already exists in guild: ${guildID}`);
} else {
log(`startUpdateTimer | ${guildID} | no current updater`);
discordLog(`Starting update timer in guild: ${guildID}`);
Expand All @@ -492,7 +508,7 @@ function updateCalendar(guild, channel, human) {
if (!guildCalendarMessageID) {
channel.send(i18n.t("update.undefined", { lng: guild.lng }));
discordLog(`calendar undefined in ${guild.id}. Killing update timer.`);
return killUpdateTimer(guild.id, "calendar undefined");
return recreateCalendar(guild.id, channel, "calendar undefined");
}
const embed = generateCalendar(guild, channel);
if (embed === 2048) return null;
Expand All @@ -504,7 +520,7 @@ function updateCalendar(guild, channel, human) {
// If theres an updater running try and kill it.
channel.send(i18n.t("timerkilled", { lng: guild.lng }));
channel.send(i18n.t("update.not_found", { lng: guild.lng }));
killUpdateTimer(guild.id, "previous not found");
recreateCalendar(guild.id, channel, "error fetching previous");
return guild.setCalendarID("");
});
// if everything went well, set lastUpdate
Expand All @@ -526,7 +542,7 @@ function calendarUpdater(guild, channel, human) {
updateCalendar(guild, channel, human);
} catch (err) {
discordLog(`error in autoupdater in guild: ${guild.id} : ${err}`);
killUpdateTimer(guild.id, "error in autoupdater");
recreateCalendar(guild.id, channel, "error in updater");
}
}

Expand Down Expand Up @@ -1155,7 +1171,7 @@ function run(cmd, args, message) {
} else if (["stats", "info"].includes(cmd)) { displayStats(channel);
} else if (["get"].includes(cmd)) { getEvents(guild, channel);
} else if (["stop"].includes(cmd)) { killUpdateTimer(guild.id, "stop command");
} else if (["delete"].includes(cmd)) { deleteEvent(args, guild, channel);
} else if (["delete"].includes(cmd)) { channel.send("delete does not work"); //deleteEvent(args, guild, channel);
} else if (["next"].includes(cmd)) { nextEvent(guild, channel);
} else if (["reset", "debug", "deny"].includes(cmd)) { channel.send (sentByAdmin ? adminCmd(cmd, args) : "Not Admin");
} else if (["validate"].includes(cmd)) { validate(guild, channel);
Expand Down

0 comments on commit c88a4fb

Please sign in to comment.