bunch of fixes
This commit is contained in:
parent
91ae72a2ba
commit
89bc056ef3
@ -75,9 +75,13 @@ class ChannelHandler {
|
||||
error: true,
|
||||
msg: `Internal error, this has been logged.`
|
||||
};
|
||||
history.push({ author: staff.id, timestamp: Date.now(), markread: true }); // To keep track of read state
|
||||
if (!history.length) return {
|
||||
error: true,
|
||||
msg: `User has no modmail history.`
|
||||
};
|
||||
if(!history[history.length-1].markread) history.push({ author: staff.id, timestamp: Date.now(), markread: true }); // To keep track of read state
|
||||
|
||||
await channel.edit({ parentID: this.readMail.id, lockPermissions: true });
|
||||
if (channel) await channel.edit({ parentID: this.readMail.id, lockPermissions: true });
|
||||
if (!this.cache.updatedThreads.includes(target)) this.cache.updatedThreads.push(target);
|
||||
if (this.cache.queue.includes(target)) this.cache.queue.splice(this.cache.queue.indexOf(target), 1);
|
||||
return {};
|
||||
|
@ -40,8 +40,9 @@ class ModmailClient extends Client {
|
||||
this.cache.load();
|
||||
|
||||
this.logger.info(`Logging in`);
|
||||
const promise = this.ready();
|
||||
await this.login(this._options.discordToken);
|
||||
await this.ready();
|
||||
await promise;
|
||||
|
||||
this.mainServer = this.guilds.cache.get(this._options.mainGuild);
|
||||
this.bansServer = this.guilds.cache.get(this._options.bansGuild) || null;
|
||||
@ -55,8 +56,8 @@ class ModmailClient extends Client {
|
||||
});
|
||||
process.on('SIGINT', () => {
|
||||
this.logger.warn('received sigint');
|
||||
this.cache.save();
|
||||
this.cache.saveModmailHistory(this.modmail);
|
||||
//this.cache.save();
|
||||
//this.cache.saveModmailHistory(this.modmail);
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit();
|
||||
});
|
||||
|
@ -298,14 +298,44 @@ class Modmail {
|
||||
msg: `This command only works in modmail channels without arguments.`
|
||||
};
|
||||
|
||||
if (args.length) {
|
||||
|
||||
// Eventually support marking several threads read at the same time
|
||||
const [id] = args;
|
||||
let channel = null;
|
||||
const _user = await this.client.resolveUser(id, true);
|
||||
if (!args.length) ({ channel } = message);
|
||||
else if (this.cache.channels[_user.id]) channel = this.client.channels.resolve(this.cache.channels[_user.id]);
|
||||
else channel = await this.client.resolveChannel(id);
|
||||
let user = await this.client.resolveUser(id, true);
|
||||
let channel = await this.client.resolveChannel(id);
|
||||
|
||||
if (channel) {
|
||||
|
||||
const chCache = this.cache.channels;
|
||||
const result = Object.entries(chCache).find(([, val]) => {
|
||||
return val === channel.id;
|
||||
});
|
||||
|
||||
if (!result) return {
|
||||
error: true,
|
||||
msg: `That doesn't seem to be a valid modmail channel. Cache might be out of sync. **[MISSING TARGET]**`
|
||||
};
|
||||
|
||||
user = await this.client.resolveUser(result[0]);
|
||||
const response = await this.channels.markread(user.id, channel, author);
|
||||
if (response.error) return response;
|
||||
return 'Done';
|
||||
|
||||
} else if (user) {
|
||||
|
||||
const _ch = this.cache.channels[user.id];
|
||||
if (_ch) channel = await this.client.resolveChannel(_ch);
|
||||
|
||||
const response = await this.channels.markread(user.id, channel, author);
|
||||
if (response.error) return response;
|
||||
return 'Done';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const { channel } = message;
|
||||
const chCache = this.cache.channels;
|
||||
const result = Object.entries(chCache).find(([, val]) => {
|
||||
return val === channel.id;
|
||||
|
@ -86,7 +86,7 @@ class Resolver {
|
||||
|
||||
if (typeof resolveables === 'string') resolveables = [resolveables];
|
||||
if (resolveables.length === 0) return false;
|
||||
if (!guild) return false;
|
||||
if (!guild) guild = this.client.mainServer;
|
||||
const CM = guild.channels;
|
||||
const resolved = [];
|
||||
|
||||
|
@ -25,7 +25,7 @@ class Logs extends Command {
|
||||
}
|
||||
|
||||
const { member, channel } = message;
|
||||
const history = await this.client.modmail.loadHistory(user.id);
|
||||
const history = await this.client.cache.loadModmailHistory(user.id);
|
||||
if (!history.length) return 'Not found in modmail DB';
|
||||
const page = this.paginate([...history].filter((e) => !e.markread).reverse(), pageNr, 10);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user