Adding checks for @usernames

This commit is contained in:
Raven Scott 2022-12-07 14:42:04 -05:00
parent 222ecf1d76
commit 76b18f3fab
4 changed files with 224 additions and 475 deletions

1
cache/17205852 vendored Normal file
View File

@ -0,0 +1 @@
{"pwd":"/"}

View File

@ -25,3 +25,72 @@
2022.12.07, 17:55:56.0772 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 17:55:56.0791 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 17:55:56.0791 UTC -> ------Order Process Completed--------
2022.12.07, 19:04:31.0332 UTC -> ------New Order Recived--------
2022.12.07, 19:04:31.0337 UTC -> 1600528742396399616,1600528742396399616,1600528742396399616,ubuntu,1600528742396399616
2022.12.07, 19:04:31.0337 UTC -> Attempting to Generate the User
2022.12.07, 19:04:31.0337 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:04:32.0233 UTC -> Ports selected: 28190-28194
2022.12.07, 19:04:32.0233 UTC -> Adding user to the customer team for access...
2022.12.07, 19:04:32.0669 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:04:32.0690 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:04:32.0690 UTC -> ------Order Process Completed--------
2022.12.07, 19:08:06.0451 UTC -> ------New Order Recived--------
2022.12.07, 19:08:06.0456 UTC -> 1600528742396399616,1600528742396399616,1600528742396399616,ubuntu,1600528742396399616
2022.12.07, 19:08:06.0456 UTC -> Attempting to Generate the User
2022.12.07, 19:08:06.0456 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:08:07.0351 UTC -> Ports selected: 36703-36707
2022.12.07, 19:08:07.0352 UTC -> Adding user to the customer team for access...
2022.12.07, 19:08:07.0774 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:08:07.0793 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:08:07.0793 UTC -> ------Order Process Completed--------
2022.12.07, 19:10:41.0477 UTC -> ------New Order Recived--------
2022.12.07, 19:10:41.0482 UTC -> 1600528742396399616,1600528742396399616,1600528742396399616,ubuntu,1600528742396399616
2022.12.07, 19:10:41.0483 UTC -> Attempting to Generate the User
2022.12.07, 19:10:41.0483 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:10:42.0642 UTC -> Ports selected: 13918-13922
2022.12.07, 19:10:42.0642 UTC -> Adding user to the customer team for access...
2022.12.07, 19:10:43.0068 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:10:43.0087 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:10:43.0087 UTC -> ------Order Process Completed--------
2022.12.07, 19:12:26.0463 UTC -> ------New Order Recived--------
2022.12.07, 19:12:26.0468 UTC -> 1600528742396399616,1600528742396399616,1600528742396399616,ubuntu,1600528742396399616
2022.12.07, 19:12:26.0469 UTC -> Attempting to Generate the User
2022.12.07, 19:12:26.0469 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:12:27.0068 UTC -> Ports selected: 36321-36325
2022.12.07, 19:12:27.0069 UTC -> Adding user to the customer team for access...
2022.12.07, 19:12:27.0473 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:12:27.0492 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:12:27.0492 UTC -> ------Order Process Completed--------
2022.12.07, 19:16:07.0456 UTC -> ------New Order Recived--------
2022.12.07, 19:16:07.0461 UTC -> 17205852,17205852,17205852,ubuntu,17205852
2022.12.07, 19:16:07.0461 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:16:07.0461 UTC -> Attempting to Generate the User
2022.12.07, 19:16:08.0304 UTC -> Ports selected: 31014-31018
2022.12.07, 19:16:08.0305 UTC -> Adding user to the customer team for access...
2022.12.07, 19:17:35.0430 UTC -> ------New Order Recived--------
2022.12.07, 19:17:35.0435 UTC -> 17205852,17205852,17205852,ubuntu,17205852
2022.12.07, 19:17:35.0435 UTC -> Attempting to Generate the User
2022.12.07, 19:17:35.0435 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:17:36.0706 UTC -> Ports selected: 12382-12386
2022.12.07, 19:17:36.0706 UTC -> Adding user to the customer team for access...
2022.12.07, 19:17:37.0073 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:17:37.0093 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:17:37.0093 UTC -> ------Order Process Completed--------
2022.12.07, 19:20:55.0500 UTC -> ------New Order Recived--------
2022.12.07, 19:20:55.0506 UTC -> 1600528742396399616,1600528742396399616,1600528742396399616,ubuntu,1600528742396399616
2022.12.07, 19:20:55.0506 UTC -> Attempting to Generate the User
2022.12.07, 19:20:55.0506 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:20:56.0038 UTC -> Ports selected: 39348-39352
2022.12.07, 19:20:56.0039 UTC -> Adding user to the customer team for access...
2022.12.07, 19:20:56.0380 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:20:56.0399 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:20:56.0399 UTC -> ------Order Process Completed--------
2022.12.07, 19:38:23.0491 UTC -> ------New Order Recived--------
2022.12.07, 19:38:23.0496 UTC -> 17205852,17205852,17205852,ubuntu,17205852
2022.12.07, 19:38:23.0496 UTC -> Attempting to Generate the User
2022.12.07, 19:38:23.0496 UTC -> Starting network scan...selecting 6.
2022.12.07, 19:38:24.0372 UTC -> Ports selected: 34528-34532
2022.12.07, 19:38:24.0373 UTC -> Adding user to the customer team for access...
2022.12.07, 19:38:24.0878 UTC -> Adding user to the resource control to lock out other customers
2022.12.07, 19:38:24.0902 UTC -> User Successfully Added to ACL, Container is ready for use!
2022.12.07, 19:38:24.0902 UTC -> ------Order Process Completed--------

550
show.js
View File

@ -1,491 +1,109 @@
const { Embed } = require("discord.js");
require('dotenv').config()
var portastic = require('portastic');
var unirest = require('unirest');
let ram
let vram
let cpus
var generator = require('generate-password');
var moment = require('moment');
const jsonfile = require('jsonfile')
let banned = 0
const fs = require("fs");
const dateFormat = require("dateformat");
require('dotenv').config()
const cmd = require('cmd-promise')
var portastic = require('portastic');
const { stderr } = require("process");
let jsonfile = require('jsonfile')
let rand = Math.floor(Math.random() * 99999999999999);
let code
let ifApt
const date = require('date-and-time');
const now = new Date();
const { EmbedBuilder } = require('discord.js');
const Dockerode = require('simple-dockerode');
var docker = new Dockerode({ socketPath: '/var/run/docker.sock' });
let finished
const { ActionRowBuilder, SelectMenuBuilder } = require('discord.js');
const moji = require('randmoji');
let end = "<=================================END===========================>"
module.exports = {
name: "x",
description: "Execute a command non-interactively.",
options: [{
"name": "cmd",
"description": "Command to Execute",
"required": true,
"type": 3 // 6 is type USER
}],
name: "destroy",
description: "Destroys your Container.",
run: async (client, interaction) => {
console.log("RUN")
await cmd('bash /home/opc/check_exist.sh ' + interaction.user.id).then(out => {
console.log('out =', out)
if (out.stdout != 1) {
(async () => {
finished = 1
console.log(end)
// await interaction.deferReply();
//await interaction.editReply(`Please wait... lets make sure this is what you want to do...`);
const row = new ActionRowBuilder()
.addComponents(
new SelectMenuBuilder()
.setCustomId('selectDestroy')
.setPlaceholder('To destroy or not destroy?')
.addOptions([
{
label: 'Destroy IT!',
description: 'Remove the container and ALL of its DATA!',
value: 'Destroy',
},
{
label: 'No, please do not destroy my precious data.',
description: 'This will cancel the command',
value: 'Action Canceled.',
},
]),
);
await interaction.editReply({ content: 'Use the menu below to choose an action.', components: [row] });
let submitted = 0;
// await interaction.reply({ content: 'Pong!', components: [row] });
client.on('interactionCreate', interaction => {
if (submitted == 1) return
if (!interaction.isSelectMenu()) return;
return await interaction.editReply("Sorry, you do not have a container currently, generate one using /generate")
})();
if (interaction.customId === 'selectDestroy') {
}
}).catch(err => {
console.log('err =', err)
})
console.log("Begin Done")
if (finished == 1) {
finished = 0
return
} else {
// await interaction.deferReply();
const path = 'cache/' + interaction.user.id
const isNotDefined = require("is-not-defined");
if (isNotDefined(interaction.options._hoistedOptions)) {
(async () => {
await interaction.editReply("You must supply a command.")
})();
return
}
let code = interaction.options._hoistedOptions[0].value
if (code.startsWith("apt install") || code.startsWith("yum install")) {
if (!code.includes("-y")) {
code = code + " -y"
console.log(code)
}
}
if (code.startsWith("pacman install")) {
if (!code.includes("--noconfirm")) {
code = code + " --noconfirm"
console.log(code)
}
}
if (code.startsWith("neofetch")) {
code = "neofetch --stdout"
}
if (fs.existsSync(path)) {
console.log("")
}
else {
console.log("No Channel PWD Found! Generating!")
fs.writeFile('./cache/' + interaction.user.id, "{\"pwd\":\"/\"}", function (err) {
});
}
commandToRun = code
if (commandToRun == "yes") return console.log("yes Blocked")
/**
*
* Start of Print Working Directory
*
*/
if (commandToRun == "pwd") {
goNoFurther = true
// check for channel pwd support file
if (fs.existsSync(path)) {
console.log("Channel PWD is active")
jsonfile = require('jsonfile')
jsonfile.readFile(path, function (err, pwdata) {
// console.log(pwdata)
(async () => {
await interaction.editReply("```" + pwdata.pwd + "```")
})();
goNoFurther = false;
if (err) console.error(err)
})
}
function escapeDoubleQuotes(str) {
return str.replace(/\\([\s\S])|(")/g, "\\$1$2"); // thanks @slevithan!
}
}
/**
*
* Main
*
*/
if (commandToRun == "pwd") return
// /**
// *
// * Start of Write
// *
// */
// console.log("cmd: " + commandToRun)
// if (commandToRun.startsWith("write")) {
// const echoFile = require('write');
// const cmd = require('cmd-promise')
// re = /\{([\s\S)]+)\}/;
// re2 = /\^(.*)\^/;
// if (commandToRun.toString().includes("\n")) console.log("YES! BREAK")
// let cdcmdtest = commandToRun // First index is removed and array is returned.
// jsonfile.readFile(path, function (err, pwdata) {
// if (err) console.error(err)
// // Regular Expression To find Sections fo command
// let codeToSend = cdcmdtest.match(re)[1]; // yes, start at 0, not 1. I hate that too.
// console.log("codeToSend: " + codeToSend)
// let fileToSend = cdcmdtest.match(re2)[1]; // yes, start at 0, not 1. I hate that too.
// console.log("file: " + fileToSend)
// // let usrcmd = cdcmdtest.slice(0).join(" ");
// jsonfile.readFile(path, function (err, pwdata) {
// if (err) console.error(err)
// //await interaction.editReply(pwdata.pwd);
// const cmd = require('cmd-promise')
// // let usrcmd = cdcmdtest.slice(0).join(" ");
// console.log("/tmp/tmpfile/" + rand + "/" + fileToSend)
// echoFile.sync("/tmp/tmpfile/" + rand + "/" + fileToSend, codeToSend, {
// newline: true
// });
// console.log('docker cp ' + "/tmp/tmpfile/" + rand + "/" + fileToSend + ' ' + interaction.user.id + ':' + pwdata.pwd)
// cmd('docker cp ' + "/tmp/tmpfile/" + + rand + "/" + fileToSend + ' ' + interaction.user.id + ':' + pwdata.pwd).then(out => {
// console.log('out =', out)
// try {
// fs.unlinkSync("/tmp/tmpfile/" + + rand + "/" + fileToSend)
// console.log("tmpfileremoved")
// rand = Math.floor(Math.random() * 99999999999999);
// } catch (err) {
// console.error(err)
// }
// }).catch(err => {
// console.log('err =', err)
// })
// (async () => {
// await interaction.editReply("File Saved as " + fileToSend);
// })();
// })
// })
// }
/**
*
* Start of CDX
*
*/
// if (commandToRun == "gobk") {
// // check for channel pwd support file
// if (fs.existsSync(path)) {
// console.log("Channel PWD is active")
// jsonfile.readFile(path, function (err, pwdata) {
// if (err) console.error(err)
// console.log(RemoveLastDirectoryPartOf(pwdata.pwd))
// //console.log(dir)
// if (RemoveLastDirectoryPartOf(pwdata.pwd).length == 0) {
// obj = {
// pwd: "/"
// }
// } else {
// obj = {
// pwd: RemoveLastDirectoryPartOf(pwdata.pwd)
// }
// }
// jsonfile.writeFile(path, obj, function (err) {
// (async () => {
// await interaction.editReply(obj.pwd);
// })();
// if (err) console.error(err)
// })
// });
// function RemoveLastDirectoryPartOf(the_url) {
// var the_arr = the_url.split('/');
// the_arr.pop();
// return (the_arr.join('/'));
// }
// function startsWith(str, word) {
// return str.lastIndexOf(word, 0) === 0;
// }
// }
// }
/**
*
* End of CDX
*
*/
/**
*
* Start of CD
*
*/
if (commandToRun.startsWith("cd")) {
console.log("test")
argscmd = interaction.options._hoistedOptions[0].value
if (argscmd == "..") {
if (interaction.values[0].includes("Canceled")) {
(async () => {
await interaction.editReply("please use the gobk command to go back a directory")
// await interaction.reply("OK! No action taken!")
(async () => {
await interaction.update({ content: interaction.values[0] + " No action taken!", components: [] });
})();
return console.log(end)
})();
} else {
(async () => {
await interaction.update({ content: interaction.values[0] + " was selected, destroying the container, please wait...", components: [] });
})();
return
}
// check for channel pwd support file
if (interaction.values[0] == "Destroy") {
cmd('docker stop ' + interaction.user.id + " && docker rm " + interaction.user.id).then(out => {
console.log('out =', out)
const netConfig = '/home/opc/netcache/' + interaction.user.id + ".network"
try {
fs.unlinkSync(netConfig)
console.log("Network Config Removed!")
} catch(err) {
console.log("No Config to remove")
}
if (fs.existsSync(path)) {
console.log("Channel PWD is active")
jsonfile = require('jsonfile')
jsonfile.readFile(path, function (err, pwdata) {
let argscmd = commandToRun.replace("cd ", "")
let dir = argscmd; // yes, start at 0, not 1. I hate that too.
if (startsWith(argscmd, "/") == false) {
const cmd = require('cmd-promise')
if (!argscmd) {
(async () => {
await interaction.editReply("Give my Syntax Please")
})();
return
}
let dir = commandToRun; // yes, start at 0, not 1. I hate that too.
let data
jsonfile.readFile(path, function (err, pwdata) {
if (err) console.error(err)
console.log(dir)
data = pwdata.pwd + "/" + argscmd
if (pwdata.pwd == "/") {
data = "/" + argscmd
}
if (argscmd == "~") {
data = "/root"
}
if (argscmd.includes("~") && argscmd.includes("/")) {
data = "/root" + "/" + argscmd.replace("~", "")
}
if (argscmd.includes("..") || argscmd.includes("../")) { // check if the user is trying to go back a directory
console.log(argscmd.split("../"))
console.log("user wants to go back " + argscmd.split("../").length + " directories")
function RemoveLastDirectoryPartOf(the_url, num) {
var the_arr = the_url.split('/');
the_arr.splice(-num, num)
return (the_arr.join('/'));
}
data = RemoveLastDirectoryPartOf(pwdata.pwd, argscmd.split("../").length - 1)
}
let final = data.replace(/([^:]\/)\/+/g, "$1")
console.log(final)
const obj = {
pwd: final
}
jsonfile.writeFile(path, obj, function (err) {
(async () => {
await interaction.editReply("Directory Changed to: " + final)
})();
if (err) console.error(err)
})
});
} else {
jsonfile.readFile(path, function (err, pwdata) {
if (err) console.error(err)
console.log('dir:' + dir)
//onsole.log(dir)
const obj = {
pwd: dir.replace(/([^:]\/)\/+/g, "$1")
}
jsonfile.writeFile(path, obj, function (err) {
if (err) console.error(err)
})
goNoFurther = false;
});
const date = require('date-and-time');
const now = new Date();
const embed = new EmbedBuilder()
.setTitle("🤯 The container was destroyed!")
.setDescription(`You may generate a new one if you would like using /generate at any time!`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
submitted = 1
await interaction.editReply("󠀠");
await interaction.editReply({ embeds: [embed] });
console.log(end)
})();
}).catch(err => {
if (err.toString().includes("such")) {
(async () => {
await interaction.editReply("Directory Changed to: " + dir.replace(/([^:]\/)\/+/g, "$1"))
console.log("A container does not exist to destroy")
await interaction.editReply("A container does not currently exist to destroy.");
console.log(end)
})();
}
function RemoveLastDirectoryPartOf(the_url) {
var the_arr = the_url.split('/');
the_arr.pop();
return (the_arr.join('/'));
}
function startsWith(str, word) {
return str.lastIndexOf(word, 0) === 0;
}
console.log('err =', err)
})
}
}
/**
*
* End of CD
*
*/
if (commandToRun.startsWith("cd")) return console.log("Skipped At Main")
if (commandToRun.startsWith("write")) return
if (commandToRun == "gobk") return
if (fs.existsSync(path)) {
function RemoveLastDirectoryPartOf(the_url) {
var the_arr = the_url.split('/');
the_arr.pop();
return (the_arr.join('/'));
}
console.log("Channel PWD is active")
jsonfile.readFile(path, function (err, pwdata) {
console.log(pwdata)
if (code == "neofetch") {
code = "neofetch --stdout --color_blocks off"
}
if (code.startsWith("apt")) {
ifApt = "-y"
} else if (code.startsWith("yum")) {
ifApt = "-y"
}
else if (code.startsWith("pacman")) {
ifApt = "--noconfirm"
} else if (code.startsWith("apt-get")) {
ifApt = "-y"
}
else {
ifApt = ""
}
if (code.includes("~")) {
code = code.replace("~", "/root")
}
if (code.includes("..")) {
pwdata.pwd = RemoveLastDirectoryPartOf(pwdata.pwd)
}
// if (code.includes("../")) { // check if the user is trying to go back a directory
// function RemoveLastDirectoryPartOf(the_url, num) {
// var the_arr = the_url.split('/');
// the_arr.splice(-num, num)
// return (the_arr.join('/'));
// }
// console.log(argscmd.split("../"))
// console.log("user wants to go back " + argscmd.split("../").length -1 + " directories in their command")
// pwddata.pwd = RemoveLastDirectoryPartOf(pwdata.pwd, argscmd.split("../").length - 1)
// }
const customerContainer = docker.getContainer(interaction.user.id);
// Simple to grab the stdout and stderr.
customerContainer.exec(['/bin/bash', '-c', 'cd ' + pwdata.pwd + ' && ' + commandToRun], { stdout: true, stderr: true }, (err, out) => {
if (typeof (out) !== 'undefined') {
console.log(out.stdout)
if (out.inspect.ExitCode !== 0) {
if (out.stderr.includes("syntax error")) {
(async () => {
await interaction.editReply("```" + "There is an error in your syntax, please try again." + "```")
console.log(end)
})();
} else {
(async () => {
return await interaction.editReply("```" + out.stderr + "```")
console.log(end)
})();
}
}
if (out.inspect.ExitCode == 0) {
if (!out.stdout) {
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Command Executed Successfully!')
.setDescription('```' + commandToRun + ' has completed.```')
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
return await interaction.editReply({ embeds: [mainEmbed] })
console.log(end)
})();
} else {
if (out.stdout.length > 2020) {
fs.writeFile('/tmp/paste', "Command: " + code.replace("--stdout --color_blocks off", "") + " | Container Owner: " + interaction.user.username + "\n" + out.stdout, err => {
if (err) {
console.error(err)
return
}
})
cmd("sleep 2; cat /tmp/paste | dpaste").then(pasteout => {
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.addFields(
{ name: 'Please check the below output log:', value: pasteout.stdout.replace("Pro tip: you can password protect your paste just by typing a username and password after your paste command.", "").replace("Paste Saved: ", "").replace("-------------------------------------------------------", "") },
).setTitle("Container Owner: " + interaction.user.username)
.setDescription("The command: " + code.replace("--stdout --color_blocks off", "") + " was too large for discord.")
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
console.log(end)
return await interaction.editReply({ embeds: [mainEmbed] })
})();
})
}
else {
// console.log("ahah " + code)
if (code.includes("dpaste")) {
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.addFields(
{ name: 'View your Paste at the link below!', value: out.stdout.replace("Pro tip: you can password protect your paste just by typing a username and password after your paste command.", "").replace("Paste Saved: ", "").replace("-------------------------------------------------------", "") },
{ name: 'Pro Tip!', value: "You can protect your paste by typing a username and password after dpaste." },
).setTitle("Paste Saved!")
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
(async () => {
return await interaction.editReply({ embeds: [mainEmbed] })
console.log(end)
})();
return
}
if (commandToRun.startsWith("cowsay") || commandToRun.startsWith("figlet")) {
(async () => {
await interaction.editReply("```" + out.stdout + "```")
})();
return
}
if (code.includes("figlet") || code.includes("figlet")) {
(async () => {
return await interaction.editReply("```" + out.stdout + "```")
console.log(end)
})();
}
//<@UserID NUMBER>
(async () => {
await interaction.editReply("```" + "Command: " + code.replace("--stdout --color_blocks off", "") + " | Container Owner: " + interaction.user.username + "\n" + out.stdout + "```")
console.log("<=================================END===========================>")
})();
}
}
}
} else {
(async () => {
await interaction.editReply("```" + "Your container either needs to be generated or is not running." + "```")
return console.log(end)
})();
}
})
})
}
}
},
};
})
}
}

View File

@ -25,7 +25,7 @@ const config = {
consumer_secret: process.env.TWITTER_API_SECRET_KEY,
access_token: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
timeout_ms: 60 * 1000,
timeout_ms: 60 * 1000000,
strictSSL: true,
};
const T = new Twit(config);
@ -124,7 +124,7 @@ async function getMentionedTweet() {
console.log("User ID: " + userID)
if (userID == "1600528742396399616") return
/////////////////////////////GENERATE
if (response.data.text.includes(`generate`)) {
cmd(`node /home/opc/genmulti_twit.js` + " " + userID + " " + userID + " " + userID + " ubuntu " + userID).then(out => {
@ -145,8 +145,8 @@ async function getMentionedTweet() {
console.log('out =', out.stdout)
const reply = "Generated!" //get the joke from the openai api
await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
const reply = "Generated!\n The container will be removed in 7 days!" //get the joke from the openai api
return await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
})();
}).catch(err => {
@ -159,10 +159,9 @@ async function getMentionedTweet() {
})
}).catch(err => {
(async () => {
console.log(err)
(async () => {
const reply = "You have a container!" //get the joke from the openai api
await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
return await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
})(); console.log(end)
})();
console.log(err)
@ -176,10 +175,52 @@ async function getMentionedTweet() {
if (response.data.text.includes(`destroy`)) {
cmd('docker stop ' + userID + " && docker rm " + userID).then(out => {
console.log('out =', out)
const netConfig = '/home/opc/netcache/' + userID + ".network"
try {
fs.unlinkSync(netConfig)
console.log("Network Config Removed!")
} catch(err) {
console.log("No Config to remove")
}
const now = new Date();
(async () => {
const reply = "The container was destroyed.\n Come back again!" //get the joke from the openai api
await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
return console.log(end)
})();
}).catch(err => {
if (err.toString().includes("such")) {
(async () => {
const reply = "No Container can be destroyed." //get the joke from the openai api
await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
return console.log(end)
})();
}
console.log('err =', err)
})
}
// if (response.data.text.includes(`exec`)) {
const tweet = JSON.stringify(response.includes.tweets[0].text, null, 2).replace("exec ", "").replace("@twit-linux ", ""); //remove the urls and double quotes from the tweet and trim the spaces
console.log("RUN")
if (tweet.includes("destroy")) return
if (tweet.includes("generate")) return
await cmd('bash /home/opc/check_exist.sh ' + userID).then(out => {
console.log('out =', out)
if (out.stdout != 1) {
@ -204,7 +245,21 @@ async function getMentionedTweet() {
const path = 'cache/' + userID
let code = tweet.replace("@twit_liux ", "").replace("exec ", "").replace(/['"]+/g, '')
let test = tweet.replace("@twit_liux ", "").replace("exec ", "").replace(/['"]+/g, '').split(" ")
const result = test.filter(word => !word.startsWith("@"));
let final = result.join(" ")
let code = final
console.log("F: " + final)
if (code.startsWith("apt install") || code.startsWith("yum install")) {
if (!code.includes("-y")) {
code = code + " -y"
@ -383,6 +438,11 @@ async function getMentionedTweet() {
* End of CD
*
*/
if (commandToRun.startsWith("destroy")) return
if (commandToRun.startsWith("generate")) return
if (commandToRun.startsWith("cd")) return console.log("Skipped At Main")
if (commandToRun.startsWith("write")) return
if (commandToRun == "gobk") return
@ -434,7 +494,6 @@ async function getMentionedTweet() {
// pwddata.pwd = RemoveLastDirectoryPartOf(pwdata.pwd, argscmd.split("../").length - 1)
// }
const customerContainer = docker.getContainer(userID);
// Simple to grab the stdout and stderr.
customerContainer.exec(['/bin/bash', '-c', 'cd ' + pwdata.pwd + ' && ' + commandToRun], { stdout: true, stderr: true }, (err, out) => {
@ -509,9 +568,11 @@ async function getMentionedTweet() {
}
}
/////////////////////////////////////// END OF X