1
0
Fork 0

various changes

refactor/models
Matthew 2020-05-03 18:59:49 -04:00
commit 1775afb2d3
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
3 changed files with 19 additions and 34 deletions

View File

@ -17,8 +17,8 @@ export default class Limits_SetRAMNotification extends Command {
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You do not have a Cloud Account.***`); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You do not have a Cloud Account.***`);
const tier = await this.client.db.Tier.findOne({ id: account.tier }); const tier = await this.client.db.Tier.findOne({ id: account.tier });
if (Number(args[0]) >= tier.resourceLimits.ram) return message.channel.createMessage(`***${this.client.stores.emojis.error} You cannot set your notification limit to be set to or above your hard limit.***`); if (Number(args[0]) >= tier.resourceLimits.ram) return message.channel.createMessage(`***${this.client.stores.emojis.error} You cannot set your notification limit to be set to or above your hard limit.***`);
if ((Number(args[0]) < 1) && (Number(args[0]) !== -1)) return message.channel.createMessage(`***${this.client.stores.emojis.error} You cannot set your notification limit to a negative number.***`); if (Number(args[0]) < 0) return message.channel.createMessage(`***${this.client.stores.emojis.error} You cannot set your notification limit to a negative number.***`);
if (Number(args[0]) === -1) { if (Number(args[0]) === 0) {
await account.updateOne({ $set: { ramLimitNotification: -1 } }); await account.updateOne({ $set: { ramLimitNotification: -1 } });
return message.channel.createMessage(`***${this.client.stores.emojis.success} You have disabled notifications.***`); return message.channel.createMessage(`***${this.client.stores.emojis.success} You have disabled notifications.***`);
} }

View File

@ -16,31 +16,28 @@ export default class Pull extends Command {
try { try {
if (this.client.updating) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`); if (this.client.updating) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`);
this.client.updating = true; this.client.updating = true;
const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\n$ git pull\n\`\`\``); const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`);
let pull: string; let pull: string;
try { try {
pull = await this.client.util.exec('git pull', { cwd: '/opt/CloudServices' }); pull = await this.client.util.exec('git pull', { cwd: '/opt/CloudServices' });
} catch (error) { } catch (error) {
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Could not fetch latest commit***`) const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Could not fetch latest commit***\n`
.replace(/```$/, `${error.message}\n\`\`\``); + `\`\`\`\n${error.message}\n\`\`\``);
this.client.updating = false; this.client.updating = false;
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
if (pull.includes('Already up to date')) { if (pull.includes('Already up to date')) {
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***No updates available***`) const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***No updates available***`);
.replace(/```$/, `${pull}\n\`\`\``);
this.client.updating = false; this.client.updating = false;
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
if (!pull.includes('origin/master') && !pull.includes(' changed, ')) { if (!pull.includes('origin/master') && !pull.includes(' changed, ')) {
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`) const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`);
.replace(/```$/, `${pull}\n\`\`\``);
this.client.updating = false; this.client.updating = false;
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`) const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`);
.replace(/```$/, `${pull}\n$ yarn install\n\`\`\``);
const passedPull = await updateMessage.edit(continueMessage); const passedPull = await updateMessage.edit(continueMessage);
@ -49,22 +46,20 @@ export default class Pull extends Command {
install = await this.client.util.exec('yarn install', { cwd: '/opt/CloudServices' }); install = await this.client.util.exec('yarn install', { cwd: '/opt/CloudServices' });
} catch (error) { } catch (error) {
this.client.updating = false; this.client.updating = false;
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Failed to reinstall dependencies***`) const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Failed to reinstall dependencies***\n`
.replace(/```$/, `${error.message}\n\`\`\``); + `\`\`\`\n${error.message}\n\`\`\``);
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
let updatedPackages: Message; let updatedPackages: Message;
if (install.includes('Already up-to-date')) { if (install.includes('Already up-to-date')) {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`) const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`);
.replace(/```$/, `${install}\n$ yarn run build\n\`\`\``);
updatedPackages = await updateMessage.edit(updatedMessage); updatedPackages = await updateMessage.edit(updatedMessage);
} else if (install.includes('success Saved lockfile.')) { } else if (install.includes('success Saved lockfile.')) {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`) const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`);
.replace(/```$/, `${install}\n$ yarn run build\n\`\`\``);
updatedPackages = await updateMessage.edit(updatedMessage); updatedPackages = await updateMessage.edit(updatedMessage);
} else { } else {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***`) const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***\n`
.replace(/```$/, `${pull}\n\`\`\``); + `\`\`\`\n${pull}\n\`\`\``);
this.client.updating = false; this.client.updating = false;
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
@ -73,14 +68,13 @@ export default class Pull extends Command {
try { try {
build = await this.client.util.exec('yarn run build', { cwd: '/opt/CloudServices' }); build = await this.client.util.exec('yarn run build', { cwd: '/opt/CloudServices' });
} catch (error) { } catch (error) {
const updatedMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***`) const updatedMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***\n`
.replace(/```$/, `${error.message}\n\`\`\``); + `\`\`\`\n${error.message}\n\`\`\``);
this.client.buildError = true; this.client.buildError = true;
this.client.updating = false; this.client.updating = false;
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
const finalMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`) const finalMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`);
.replace(/```$/, `${build}\n\`\`\``);
this.client.updating = false; this.client.updating = false;
this.client.buildError = false; this.client.buildError = false;
return updateMessage.edit(finalMessage); return updateMessage.edit(finalMessage);

View File

@ -6,15 +6,6 @@ import { TierInterface } from '../models';
const channelID = '691824484230889546'; const channelID = '691824484230889546';
const memoryLimits = {
TIER_1_SOFT: 250,
TIER_1_HARD: 300,
TIER_2_SOFT: 350,
TIER_2_HARD: 400,
TIER_3_SOFT: 500,
TIER_3_HARD: 550,
};
export default function memory(client: Client) { export default function memory(client: Client) {
const set = new Set<string>(); const set = new Set<string>();
setInterval(async () => { setInterval(async () => {
@ -29,7 +20,7 @@ export default function memory(client: Client) {
const userLimits: { soft?: number, hard?: number } = {}; const userLimits: { soft?: number, hard?: number } = {};
const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec(); const tier: TierInterface = await client.db.Tier.findOne({ id: acc.tier }).lean().exec();
userLimits.soft = acc.ramLimitNotification; userLimits.soft = acc.ramLimitNotification;
userLimits.hard = tier.resourceLimits.ram + 10; userLimits.hard = tier.resourceLimits.ram;
if (memoryConversion <= userLimits.soft) { if (memoryConversion <= userLimits.soft) {
set.delete(acc.username); set.delete(acc.username);
} }
@ -76,7 +67,7 @@ export default function memory(client: Client) {
embed.setFooter(client.user.username, client.user.avatarURL); embed.setFooter(client.user.username, client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
await client.createMessage(channelID, { embed }); await client.createMessage(channelID, { embed });
if ((memoryConversion >= acc.ramLimitNotification) && (acc.ramLimitNotification !== -1)) { if ((memoryConversion >= acc.ramLimitNotification) && (acc.ramLimitNotification !== 0)) {
const notifyEmbed = new RichEmbed() const notifyEmbed = new RichEmbed()
.setTitle('Cloud Account | Notification') .setTitle('Cloud Account | Notification')
.setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard - 10)} MB'. Please correct your usage to avoid further action.\nYou can set your notification preferences by running \`=limits set-ram-notification <preferred ram threshold in MB>\`, you can disable these notifications by running \`=limits set-ram-notification -1\`.`) .setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(memoryConversion)} MB' and your limit is '${String(userLimits.hard - 10)} MB'. Please correct your usage to avoid further action.\nYou can set your notification preferences by running \`=limits set-ram-notification <preferred ram threshold in MB>\`, you can disable these notifications by running \`=limits set-ram-notification -1\`.`)