Skip to content

Commit

Permalink
fixed faulty update, thanks to Kerberos#0002
Browse files Browse the repository at this point in the history
  • Loading branch information
mchangrh committed Jan 29, 2021
1 parent e73e4c2 commit 008dc90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions handlers/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function killUpdateTimer(guildid) {
function clean(channel, numMsg, deleteCal) {
numMsg = ((numMsg <= 97) ? numMsg+= 3 : 100); // add 3 messages from collector
const guild = new helpers.Guild(channel.guild.id);
const calMsgID = guild.getCalendar("calendarMessageId");
if (deleteCal) {
guild.setCalendarID(""); // delete calendar id
killUpdateTimer(guild.id);
Expand All @@ -94,7 +95,7 @@ function clean(channel, numMsg, deleteCal) {
channel.messages.fetch({ limit: numMsg })
.then((messages) => { //If the current calendar is deleted
messages.forEach(function(message) {
if (guild.calendarID && message.id === guild.calendarID) messages.delete(message.id); // skip calendar message
if (calMsgID && message.id === calMsgID) messages.delete(message.id); // skip calendar message
});
return channel.bulkDelete(messages, true);
});
Expand Down Expand Up @@ -429,12 +430,13 @@ function startUpdateTimer(guildid, channel, guild) {
* @param {bool} human - if command was initiated by a human
*/
function updateCalendar(guild, channel, human) {
if (guild.calendarID === "") {
const calMsgID = guild.getCalendar("calendarMessageId");
if (calMsgID === "") {
channel.send("Cannot find calendar to update, maybe try a new calendar with `!display`");
helpers.log(`calendar undefined in ${guild.id}. Killing update timer.`);
killUpdateTimer(guild.id);
}
channel.messages.fetch(guild.calendarID).then((m) => {
channel.messages.fetch(calMsgID).then((m) => {
generateCalendar(guild, channel).then((embed) => {
if (embed === 2048) return null;
m.edit({ embed });
Expand Down Expand Up @@ -475,8 +477,9 @@ function calendarUpdater(guild, channel, human) {
* @param {Snowflake} channel - Initiating channel
*/
function postCalendar(guild, channel) {
if (guild.calendarID) {
channel.messages.fetch(guild.calendarID).then((message) => { message.delete();
const guildCalMsgID = guild.getCalendar("calendarMessageId");
if (guildCalMsgID) {
channel.messages.fetch(guildCalMsgID).then((message) => { message.delete();
}).catch((err) => {
if (err.code === 10008) guild.setCalendarID("");
return helpers.log(`error fetching previous calendar in guild: ${guild.id} : ${err}`);
Expand Down
1 change: 0 additions & 1 deletion handlers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ function Guild(guildid) {
calendar.calendarMessageId = calendarID;
this.setCalendar();
};
this.calendarID = calendar.calendarMessageId;
// daymap
this.getDayMap = () => {
let dayMap = [];
Expand Down

0 comments on commit 008dc90

Please sign in to comment.