From 26ebf8afe2b17e76f65b22746088cefb63a61dba Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:20:11 +0100 Subject: [PATCH 01/11] Update index.js --- index.js | 125 ++++++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 67 deletions(-) diff --git a/index.js b/index.js index df65345..0544a09 100644 --- a/index.js +++ b/index.js @@ -1,85 +1,76 @@ const { SlashCtrl } = require('slashctrl'); const path = require('path'); - +const { Client, GatewayIntentBits } = require('discord.js'); const exec = require('./cmd/ssh'); +const db = require('./cmd/db'); -var log = console.log; - -var botToken = ''; +const botToken = ''; +const applicationId = ''; +const channelId = '1204045694164533269'; const slashCtrl = new SlashCtrl({ - token: botToken, - applicationId: '' + token: botToken, + applicationId: applicationId }); slashCtrl.publishCommandsFromFolder(path.join(__dirname, 'cmd')); -const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.on('ready', () => { - console.log(`Logged in as ${client.user.tag}!`); - - const db = require('./cmd/db'); - - var isChecking; - isChecking = false; - - setInterval(async () => { - log('> Checking vps expire'); - - if (isChecking == true) { - return console.log('already checking expire'); - } - - isChecking = true; - - var vps = await db.VPS.find({ - expiry: { - $lt: Date.now() - } - }); - - for (let ab = 0; ab < vps.length; ab++) { - var expiredVPS = vps[ab]; - const channel = client.channels.cache.get('1204045694164533269'); - if (!expiredVPS.proxID) { - console.log(`vps ${expiredVPS._id} does not have proxmox id`, expiredVPS); - - channel.send(`<@${expiredVPS.userID}> Your vps failed to create and has been removed from the database. Try again with /create in #cmds`); - - await db.VPS.deleteMany({ _id: expiredVPS._id }); - - } else { - - await exec('bash /root/remove.sh ' + expiredVPS.proxID); - - var r; - r = 'expired'; - - if (expiredVPS.hasUsed == false) { - r = 'vps was not activated in time'; - } - if (expiredVPS.hasUsed == null || expiredVPS.hasUsed == undefined) { - r = 'using alpine linux. We switched back to debian because alpine was buggy, so your vps was deleted, sorry'; - } - - channel.send(`VPS ${expiredVPS.proxID} was deleted because: ${r} - <@${expiredVPS.userID}>`); - - await db.VPS.deleteMany({ proxID: expiredVPS.proxID }); - } - } - - isChecking = false; - console.log('> Expiry check done!') + console.log(`Logged in as ${client.user.tag}!`); + startVpsExpiryCheck(); +}); - // console.log('List', vps); - }, 60 * 1000); +client.on('interactionCreate', async (interaction) => { + console.log(`> ${interaction.user.username} -> /${interaction.commandName}`); + slashCtrl.handleCommands(interaction); }); client.login(botToken); -client.on('interactionCreate', async interaction => { - console.log(`> ${interaction.user.username} -> /${interaction.commandName}`); - slashCtrl.handleCommands(interaction); -}); +async function startVpsExpiryCheck() { + console.log('> Starting VPS expiry check'); + setInterval(async () => { + try { + console.log('> Checking VPS expiry'); + const expirationThreshold = Date.now() + 3600000; // 1 hour threshold + const vps = await db.VPS.find({ expiry: { $lt: expirationThreshold } }); + + for (let i = 0; i < vps.length; i++) { + const expiredVPS = vps[i]; + const channel = client.channels.cache.get(channelId); + + if (!expiredVPS.proxID) { + console.log(`VPS ${expiredVPS._id} does not have a proxmox ID`, expiredVPS); + channel.send(`<@${expiredVPS.userID}> Your VPS failed to create and has been removed from the database. Try again with /create in #cmds`); + await db.VPS.deleteMany({ _id: expiredVPS._id }); + } else { + const expirationTime = new Date(expiredVPS.expiry); + const timeUntilExpiry = expirationTime - Date.now(); + const hoursUntilExpiry = Math.floor(timeUntilExpiry / 3600000); + let r = 'expired'; + + if (expiredVPS.hasUsed === false) { + r = 'VPS was not activated in time'; + } else if (expiredVPS.hasUsed === null || expiredVPS.hasUsed === undefined) { + r = 'Using Alpine Linux. We switched back to Debian because Alpine was buggy, so your VPS was deleted. Sorry.'; + } + + if (hoursUntilExpiry <= 1) { + channel.send(`VPS ${expiredVPS.proxID} will be deleted soon (${hoursUntilExpiry} hour(s) remaining) because: ${r} - <@${expiredVPS.userID}>`); + } else { + channel.send(`VPS ${expiredVPS.proxID} was deleted because: ${r} - <@${expiredVPS.userID}>`); + } + + await exec(`bash /root/remove.sh ${expiredVPS.proxID}`); + await db.VPS.deleteMany({ proxID: expiredVPS.proxID }); + } + } + + console.log('> Expiry check done!'); + } catch (error) { + console.error('Error occurred during VPS expiry check:', error); + } + }, 60 * 1000); +} From b9cdea840a01b637ed98cc200ab10eface7382e8 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:24:15 +0100 Subject: [PATCH 02/11] Update create.ts --- cmd/create.ts | 304 +++++++++++++++++++++----------------------------- 1 file changed, 130 insertions(+), 174 deletions(-) diff --git a/cmd/create.ts b/cmd/create.ts index 21c66bf..5fa795d 100644 --- a/cmd/create.ts +++ b/cmd/create.ts @@ -1,191 +1,147 @@ -const db = require('./db'); -const prox = require('./prox'); const { SlashCommand } = require('slashctrl'); +const { Client } = require('ssh2'); +const { generate } = require('generate-password'); +const { readFileSync } = require('fs'); +const { randomip } = require('random-ip'); +const { dayjs } = require('dayjs'); -var randomip = require('random-ip'); +class CMD extends SlashCommand { + constructor() { + super(); + this.guilds = ['1013767249884094534', '1203730039296888842']; + this.setName('create'); + this.setDescription('Create a vps'); + this.addStringOption((option) => + option.setName('name').setDescription('VPS name').setRequired(true) + ); + } -var generator = require('generate-password'); + async execute(ints) { + const userID = ints.user.id; + let user = await db.User.findOne({ userID }); + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free', + vpsLimit: 1, + }); + await user.save(); + } + const vpsCount = await db.VPS.find({ userID }); + const vpsCountLength = vpsCount.length; -class CMD extends SlashCommand { + if (!user.vpsLimit) { + user.vpsLimit = 1; + await user.save(); + } - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("create"); - this.setDescription("Create a vps"); - - this.addStringOption(option => - option.setName('name') - .setDescription('VPS name') - .setRequired(true)); + if (vpsCountLength >= user.vpsLimit) { + return ints.reply( + `You can only have ${user.vpsLimit} vps!` + ); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free', - vpsLimit: 1 - }); - await user.save(); - } - - var vpsCount = await db.VPS.find({ - userID: userID - }); - console.log(vpsCount); - vpsCount = vpsCount.length; - - if (!user.vpsLimit) { - user.vpsLimit = 1; - await user.save(); - } - - if (vpsCount >= user.vpsLimit) { - return ints.reply('You can only have '+user.vpsLimit+' vps!') - } - - var plan = user.plan; - - var ram; - var cpu; - var disk; - var minCredits; - var cost; - - var pass; - pass = generator.generate({ - length: 15, - uppercase: false, - numbers: true - }); - var name = ints.options.getString('name'); - - if (plan == 'free') { - ram = 4; - cpu = 1; - disk = 5; - minCredits = 0.01; - cost = 1; - } - - if (user.balance <= minCredits) { - return ints.reply(`You need at least $${minCredits}, but you only have $${user.balance}`); - } - - await ints.reply(`Creating...\n\n**PLEASE WAIT.** This might take a few minutes`); - - const { readFileSync } = require('fs'); - const { Client } = require('ssh2'); - - var proxId; - - var cOut; - cOut = ''; + const plan = user.plan; - var ip = randomip('10.5.0.0', 16); + let ram; + let cpu; + let disk; + let minCredits; + let cost; - const rand = (min, max) => { - return Math.round(Math.random() * (max - min)) + min; - } - var rCm; - rCm = rand(100000, 999999); - - const conn = new Client(); - conn.on('ready', () => { - console.log('Client :: ready'); - conn.exec(`/usr/bin/bash /root/make/free.sh ${pass} ${ip} ${rCm}`, (err, stream) => { - if (err) throw err; - stream.on('close', (code, signal) => { - console.log('Stream :: close :: code: ' + code + ', signal: ' + signal); - - try { - var por = ''; - - for (let ii = 1; ii<=9; ii++) { - por += `IP:3${proxId}${ii} -> 3${proxId}${ii}\n` - } - - var conns = ''; - - conns += '```\n'; - conns += `ssh root@IP -p 3${proxId}0` - conns += '\n```' - - ints.user.send(`VPS IP: IP\nSSH port: 3${proxId}0\nVPS username: root\nVPS password: ${pass}\n\n**Forwarded ports:**\n${por}\n\nConnect to it by executing the following command in a terminal:\n${conns}`); - - ints.editReply(`Created! Check your DM!`); - } catch(e) { - console.log('DM error', String(e), e); - ints.followUp(`Could not send DM! Use /list to see the details of the vps.`); - } - - - conn.end(); - }).on('data', (data) => { - console.log('STDOUT: ' + data); - - if (String(data).includes('BTTM-Done')) { - console.log('Making vps is done!', proxId); - - const dayjs = require('dayjs') - - var vps = new db.VPS({ - userID, + let pass; + pass = generate({ + length: 15, + uppercase: false, + numbers: true, + }); + const name = ints.options.getString('name'); - name, - password: pass, + if (plan === 'free') { + ram = 4; + cpu = 1; + disk = 5; + minCredits = 0.01; + cost = 1; + } - ram: ram*1024, - cpu: cpu, - disk, + if (user.balance <= minCredits) { + return ints.reply( + `You need at least $${minCredits}, but you only have $${user.balance}` + ); + } - hasUsed: false, - usedCode: rCm, - - expiry: dayjs().add(3, 'day'), - cost, + await ints.reply( + `Creating...\n\n**PLEASE WAIT.** This might take a few minutes` + ); - proxID: proxId, - ip: ip - }); - vps.save(); - - } - - if (String(data).startsWith('ID')) { - proxId = String(data).replace('ID-', ''); - proxId = String(proxId).replace('\n', ''); - console.log('Got proxmox ID:', proxId); - } else { - - cOut += String(data + '\n'); - - } - - }).stderr.on('data', (data) => { - console.log('STDERR: ' + data); - }); + const conn = new Client(); + conn.on('ready', () => { + console.log('Client :: ready'); + conn.exec( + `/usr/bin/bash /root/make/free.sh ${pass} ${randomip('10.5.0.0', 16)} ${rand( + 100000, + 999999 + )}`, + (err, stream) => { + if (err) throw err; + stream.on('close', (code, signal) => { + console.log('Stream :: close :: code: ' + code + ', signal: ' + signal); + try { + const por = []; + for (let ii = 1; ii <= 9; ii++) { + por.push(`IP:3${proxId}${ii} -> 3${proxId}${ii}\n`); + } + const conns = []; + conns.push('```\n'); + conns.push(`ssh root@IP -p 3${proxId}0`); + conns.push('\n```'); + ints.user.send( + `VPS IP: IP\nSSH port: 3${proxId}0\nVPS username: root\nVPS password: ${pass}\n\n**Forwarded ports:**\n${por}\n\nConnect to it by executing the following command in a terminal:\n${conns}` + ); + ints.editReply(`Created! Check your DM!`); + } catch (e) { + console.log('DM error', String(e), e); + ints.followUp(`Could not send DM! Use /list to see the details of the vps.`); + } + conn.end(); + }).on('data', (data) => { + console.log('STDOUT: ' + data); + if (String(data).includes('BTTM-Done')) { + console.log('Making vps is done!', proxId); + const dayjs = require('dayjs'); + const vps = new db.VPS({ + userID, + name, + password: pass, + ram: ram * 1024, + cpu: cpu, + disk, + hasUsed: false, + usedCode: rand(100000, 999999), + expiry: dayjs().add(3, 'day'), + cost, + proxID: proxId, + ip: randomip('10.5.0.0', 16), + }); + vps.save(); + } else { + cOut += String(data + '\n'); + } + }).stderr.on('data', (data) => { + console.log('STDERR: ' + data); }); - }).connect({ - host: 'IP', - port: 0, - username: '', - password: '' - }); - } - + } + ); + }).connect({ + host: 'IP', + port: 0, + username: '', + password: '', + }); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From 8df2fbd62e9f6a6a6604ea927d16a7aee44d1b21 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:25:29 +0100 Subject: [PATCH 03/11] Update delete.ts --- cmd/delete.ts | 109 ++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 70 deletions(-) diff --git a/cmd/delete.ts b/cmd/delete.ts index 23c387e..b056783 100644 --- a/cmd/delete.ts +++ b/cmd/delete.ts @@ -1,77 +1,46 @@ -const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const db = require('./db'); -class CMD extends SlashCommand { +class DeleteCommand extends SlashCommand { + constructor() { + super(); + this.guilds = ['1013767249884094534', '1203730039296888842']; + this.setName('delete'); + this.setDescription('Deletes your VPS'); + this.addIntegerOption(option => + option.setName('id').setDescription('VPS ID (found in /list)').setRequired(true) + ); + this.addBooleanOption(option => + option.setName('sure').setDescription('Are you sure you want to delete your VPS?').setRequired(true) + ); + } - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("delete"); - this.setDescription("Deletes your vps"); - - this.addIntegerOption(option => - option.setName('id') - .setDescription('VPS ID (found in /list)') - .setRequired(true)); - - this.addBooleanOption(option => - option.setName('sure') - .setDescription('Are you sure you want to delete your vps?') - .setRequired(true)); + async execute(ints) { + const userID = ints.user.id; + const user = await db.User.findOne({ userID }); + if (!user) { + user = new db.User({ userID, balance: 1, plan: 'free' }); + await user.save(); } - - async execute(ints) { - - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('id'); - var sure = ints.options.getBoolean('sure'); - - if (!sure) return ints.reply(`Cancelled destroy. User is not sure.`); - - var vps = await db.VPS.findOne({ - proxID: id - }); - - if (!vps) { - return await ints.reply(`[1] VPS ${id} not found`); - } - - if (vps.userID != ints.user.id) { - if (userID != '554344892827172884') { - return await ints.reply(`[2] No access to VPS ${id} - ${vps.userID} / ${userID}`); - } - } - - - const exec = require('./ssh'); - - await ints.deferReply(); - - await exec(`bash /root/remove.sh ${id}`); - - var dbDel = await db.VPS.deleteOne({ _id: vps._id }); - - console.log('delete', dbDel); - - ints.editReply(`VPS destroyed`); + const id = ints.options.getInteger('id'); + const sure = ints.options.getBoolean('sure'); + if (!sure) return ints.reply(`Cancelled destroy. User is not sure.`); + const vps = await db.VPS.findOne({ proxID: id }); + if (!vps) { + return await ints.reply(`[1] VPS ${id} not found`); } - + if (vps.userID !== ints.user.id) { + if (userID !== '554344892827172884') { + return await ints.reply(`[2] No access to VPS ${id} - ${vps.userID} / ${userID}`); + } + } + const exec = require('./ssh'); + await ints.deferReply(); + await exec(`bash /root/remove.sh ${id}`); + const dbDel = await db.VPS.deleteOne({ _id: vps._id }); + console.log('delete', dbDel); + ints.editReply(`VPS destroyed`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: DeleteCommand }; From 80d8d72d069f76591d13c2fad03989cc53608f3e Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:28:51 +0100 Subject: [PATCH 04/11] Update create.ts --- cmd/create.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmd/create.ts b/cmd/create.ts index 5fa795d..15c3d31 100644 --- a/cmd/create.ts +++ b/cmd/create.ts @@ -81,10 +81,7 @@ class CMD extends SlashCommand { conn.on('ready', () => { console.log('Client :: ready'); conn.exec( - `/usr/bin/bash /root/make/free.sh ${pass} ${randomip('10.5.0.0', 16)} ${rand( - 100000, - 999999 - )}`, + `/usr/bin/bash /root/make/free.sh ${pass} ${randomip('10.5.0.0', 16)} ${usedCode}`, (err, stream) => { if (err) throw err; stream.on('close', (code, signal) => { @@ -120,7 +117,7 @@ class CMD extends SlashCommand { cpu: cpu, disk, hasUsed: false, - usedCode: rand(100000, 999999), + usedCode: usedCode, expiry: dayjs().add(3, 'day'), cost, proxID: proxId, From dafa9d3623f744b45e629a63cefbd099d88df176 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:34:30 +0100 Subject: [PATCH 05/11] Update kill.ts --- cmd/kill.ts | 93 +++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/cmd/kill.ts b/cmd/kill.ts index 3292c8b..20d9a1f 100644 --- a/cmd/kill.ts +++ b/cmd/kill.ts @@ -1,59 +1,54 @@ const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const exec = require('./ssh'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("kill"); - this.setDescription("Kill your vps"); - - this.addIntegerOption(option => - option.setName('id') - .setDescription('VPS ID (found in /list)') - .setRequired(true)); + this.guilds = ["1013767249884094534", "1203730039296888842"]; + this.setName("kill"); + this.setDescription("Kill your vps"); + + this.addIntegerOption(option => + option.setName('id') + .setDescription('VPS ID (found in /list)') + .setRequired(true)); + } + + async execute(ints) { + var userID = ints.user.id; + + var user = await db.User.findOne({ + userID: userID + }); + + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free' + }); + await user.save(); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('id'); - - var vps = await db.VPS.findOne({ - userID: userID, - proxID: id - }); - - if (!vps) { - return ints.reply(`VPS ${id} not found`); - } - - - const exec = require('./ssh'); - - await ints.deferReply(); - - await exec(`pct stop ${id}`); - - ints.editReply(`VPS killed!`); + + var id = ints.options.getInteger('id'); + + var vps = await db.VPS.findOne({ + userID: userID, + proxID: id + }); + + if (!vps) { + return ints.reply(`VPS ${id} not found`); } + await ints.deferReply(); + + await exec(`pct stop ${id}`); + + ints.editReply(`VPS killed!`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From febfe02ec80efc54a266cba349b0c9e303079b25 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:35:45 +0100 Subject: [PATCH 06/11] Update restart.ts --- cmd/restart.ts | 93 ++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/cmd/restart.ts b/cmd/restart.ts index 55ae4df..27d722b 100644 --- a/cmd/restart.ts +++ b/cmd/restart.ts @@ -1,59 +1,54 @@ const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const exec = require('./ssh'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("restart"); - this.setDescription("Restart your vps"); - - this.addIntegerOption(option => - option.setName('id') - .setDescription('VPS ID (found in /list)') - .setRequired(true)); + this.guilds = ["1013767249884094534", "1203730039296888842"]; + this.setName("restart"); + this.setDescription("Restart your vps"); + + this.addIntegerOption(option => + option.setName('id') + .setDescription('VPS ID (found in /list)') + .setRequired(true)); + } + + async execute(ints) { + var userID = ints.user.id; + + var user = await db.User.findOne({ + userID: userID + }); + + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free' + }); + await user.save(); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('id'); - - var vps = await db.VPS.findOne({ - userID: userID, - proxID: id - }); - - if (!vps) { - return ints.reply(`VPS ${id} not found`); - } - - - const exec = require('./ssh'); - - await ints.deferReply(); - - await exec(`pct reboot ${id}`); - - ints.editReply(`VPS restart!`); + + var id = ints.options.getInteger('id'); + + var vps = await db.VPS.findOne({ + userID: userID, + proxID: id + }); + + if (!vps) { + return ints.reply(`VPS ${id} not found`); } + await ints.deferReply(); + + await exec(`pct reboot ${id}`); + + ints.editReply(`VPS restarted!`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From 8be59c01d1fdcb3cdc19baacdbd3586f6a539b82 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:36:45 +0100 Subject: [PATCH 07/11] Update used.ts --- cmd/used.ts | 98 +++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/cmd/used.ts b/cmd/used.ts index a91b84e..bde3eeb 100644 --- a/cmd/used.ts +++ b/cmd/used.ts @@ -1,61 +1,57 @@ const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const dayjs = require('dayjs'); +const { time } = require('discord.js'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds = [ "1203730039296888842" ]; - - this.setName("used"); - this.setDescription("Mark your vps as used"); - - this.addIntegerOption(option => - option.setName('code') - .setDescription('Code') - .setRequired(true)); + this.guilds = ["1203730039296888842"]; + this.setName("used"); + this.setDescription("Mark your vps as used"); + + this.addIntegerOption(option => + option.setName('code') + .setDescription('Code') + .setRequired(true)); + } + + async execute(ints) { + var userID = ints.user.id; + + var user = await db.User.findOne({ + userID: userID + }); + + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free' + }); + await user.save(); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('code'); - - var vps = await db.VPS.findOne({ - usedCode: id - }); - - if (!vps) { - return ints.reply(`Code ${id} not found`); - } - - const dayjs = require('dayjs') - vps.expiry = dayjs().add(1, 'day'); - vps.hasUsed = true; - - await vps.save(); - - const { time } = require('discord.js'); - - const relative = time( new Date(vps.expiry) , 'R'); - - ints.reply(`Activated vps with code ${id}!\nExpiry date: ${relative}`) + + var id = ints.options.getInteger('code'); + + var vps = await db.VPS.findOne({ + usedCode: id + }); + + if (!vps) { + return ints.reply(`Code ${id} not found`); } + vps.expiry = dayjs().add(1, 'day'); + vps.hasUsed = true; + + await vps.save(); + + const relative = time(new Date(vps.expiry), 'R'); + + ints.reply(`Activated vps with code ${id}!\nExpiry date: ${relative}`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From 41a2e6214067b95ebe98460d2f472d3d63d4becf Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:37:38 +0100 Subject: [PATCH 08/11] Update renew.ts --- cmd/renew.ts | 98 +++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/cmd/renew.ts b/cmd/renew.ts index 9d78c54..74d0ecc 100644 --- a/cmd/renew.ts +++ b/cmd/renew.ts @@ -1,61 +1,57 @@ const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const dayjs = require('dayjs'); +const { time } = require('discord.js'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("renew"); - this.setDescription("Renew your vps"); - - this.addIntegerOption(option => - option.setName('id') - .setDescription('VPS ID (found in /list)') - .setRequired(true)); + this.guilds = ["1013767249884094534", "1203730039296888842"]; + this.setName("renew"); + this.setDescription("Renew your vps"); + + this.addIntegerOption(option => + option.setName('id') + .setDescription('VPS ID (found in /list)') + .setRequired(true)); + } + + async execute(ints) { + var userID = ints.user.id; + + var user = await db.User.findOne({ + userID: userID + }); + + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free' + }); + await user.save(); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('id'); - - var vps = await db.VPS.findOne({ - userID: userID, - proxID: id - }); - - if (!vps) { - return ints.reply(`VPS ${id} not found`); - } - - const dayjs = require('dayjs') - vps.expiry = dayjs().add(3, 'day'); - - await vps.save(); - - const { time } = require('discord.js'); - - const relative = time( new Date(vps.expiry) , 'R'); - - ints.reply(`Renewed vps ${id}!\nExpiry date: ${relative}`) + + var id = ints.options.getInteger('id'); + + var vps = await db.VPS.findOne({ + userID: userID, + proxID: id + }); + + if (!vps) { + return ints.reply(`VPS ${id} not found`); } + vps.expiry = dayjs().add(3, 'day'); + + await vps.save(); + + const relative = time(new Date(vps.expiry), 'R'); + + ints.reply(`Renewed vps ${id}!\nExpiry date: ${relative}`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From 056bd213ff8e5ca3fd004d73e619301a4aba8013 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:38:10 +0100 Subject: [PATCH 09/11] Update ping.ts --- cmd/ping.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/cmd/ping.ts b/cmd/ping.ts index 7a17bd6..0d6be15 100644 --- a/cmd/ping.ts +++ b/cmd/ping.ts @@ -1,20 +1,17 @@ const { SlashCommand } = require('slashctrl'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds= ["1013767249884094534", "1203730039296888842"]; - - this.setName("ping"); - this.setDescription("Check if the bot is online"); - } - - execute(interaction) { - interaction.reply('**Pong** :coin: :D') - } + this.guilds = ["1013767249884094534", "1203730039296888842"]; + this.setName("ping"); + this.setDescription("Check if the bot is online"); + } + execute(interaction) { + interaction.reply('**Pong** :coin: :D'); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From d421edd7481868e77462a771b3265f95f888eb9c Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:39:37 +0100 Subject: [PATCH 10/11] Update start.ts --- cmd/start.ts | 93 +++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/cmd/start.ts b/cmd/start.ts index 48fb7a1..a63e88d 100644 --- a/cmd/start.ts +++ b/cmd/start.ts @@ -1,59 +1,54 @@ const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const exec = require('./ssh'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("start"); - this.setDescription("Start your vps"); - - this.addIntegerOption(option => - option.setName('id') - .setDescription('VPS ID (found in /list)') - .setRequired(true)); + this.guilds = ["1013767249884094534", "1203730039296888842"]; + this.setName("start"); + this.setDescription("Start your vps"); + + this.addIntegerOption(option => + option.setName('id') + .setDescription('VPS ID (found in /list)') + .setRequired(true)); + } + + async execute(ints) { + var userID = ints.user.id; + + var user = await db.User.findOne({ + userID: userID + }); + + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free' + }); + await user.save(); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('id'); - - var vps = await db.VPS.findOne({ - userID: userID, - proxID: id - }); - - if (!vps) { - return ints.reply(`VPS ${id} not found`); - } - - - const exec = require('./ssh'); - - await ints.deferReply(); - - await exec(`pct start ${id}`); - - ints.editReply(`> Your vps is now online.`); + + var id = ints.options.getInteger('id'); + + var vps = await db.VPS.findOne({ + userID: userID, + proxID: id + }); + + if (!vps) { + return ints.reply(`VPS ${id} not found`); } + await ints.deferReply(); + + await exec(`pct start ${id}`); + + ints.editReply(`> Your vps is now online.`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD }; From 0b806892270f23a85b677aac330e713961faaa92 Mon Sep 17 00:00:00 2001 From: JustADeve <142085654+JustADeve@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:40:17 +0100 Subject: [PATCH 11/11] Update stop.ts --- cmd/stop.ts | 93 +++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/cmd/stop.ts b/cmd/stop.ts index 0d800a7..aba39bb 100644 --- a/cmd/stop.ts +++ b/cmd/stop.ts @@ -1,59 +1,54 @@ const db = require('./db'); const { SlashCommand } = require('slashctrl'); +const exec = require('./ssh'); class CMD extends SlashCommand { + constructor() { + super(); - constructor() { - super(); - - this.guilds = ["1013767249884094534", "1203730039296888842"]; - - this.setName("stop"); - this.setDescription("Stop your vps"); - - this.addIntegerOption(option => - option.setName('id') - .setDescription('VPS ID (found in /list)') - .setRequired(true)); + this.guilds = ["1013767249884094534", "1203730039296888842"]; + this.setName("stop"); + this.setDescription("Stop your vps"); + + this.addIntegerOption(option => + option.setName('id') + .setDescription('VPS ID (found in /list)') + .setRequired(true)); + } + + async execute(ints) { + var userID = ints.user.id; + + var user = await db.User.findOne({ + userID: userID + }); + + if (!user) { + user = new db.User({ + userID, + balance: 1, + plan: 'free' + }); + await user.save(); } - - async execute(ints) { - var userID = ints.user.id; - - var user = await db.User.findOne({ - userID: userID - }); - - if (!user) { - user = new db.User({ - userID, - balance: 1, - plan: 'free' - }); - await user.save(); - } - - var id = ints.options.getInteger('id'); - - var vps = await db.VPS.findOne({ - userID: userID, - proxID: id - }); - - if (!vps) { - return ints.reply(`VPS ${id} not found`); - } - - - const exec = require('./ssh'); - - await ints.deferReply(); - - await exec(`pct shutdown ${id}`); - - ints.editReply(`VPS stopped!`); + + var id = ints.options.getInteger('id'); + + var vps = await db.VPS.findOne({ + userID: userID, + proxID: id + }); + + if (!vps) { + return ints.reply(`VPS ${id} not found`); } + await ints.deferReply(); + + await exec(`pct shutdown ${id}`); + + ints.editReply(`VPS stopped!`); + } } -module.exports = { default: CMD }; \ No newline at end of file +module.exports = { default: CMD };