Add files via upload
This commit is contained in:
18
bot/commands/banIP.js
Normal file
18
bot/commands/banIP.js
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
command: 'banip',
|
||||
description: 'Ban an IP Address from your service',
|
||||
syntax: '{PREFIX}banip [IP_ADDRESS]',
|
||||
execute: async (_this, msg, args) => {
|
||||
if (!args.join(' ')) return msg.channel.createMessage('No arguments were given');
|
||||
const ipAddress = args.join(' ');
|
||||
const exists = _this.db.get('bans').find({ ip: ipAddress }).value();
|
||||
if (exists === undefined) {
|
||||
msg.channel.createMessage(`Banning IP \`${ipAddress}\`...`);
|
||||
_this.db.get('bans')
|
||||
.push({ ip: ipAddress })
|
||||
.write();
|
||||
} else {
|
||||
msg.channel.createMessage('This IP Address is already banned');
|
||||
}
|
||||
},
|
||||
};
|
17
bot/commands/deleteFile.js
Normal file
17
bot/commands/deleteFile.js
Normal file
@ -0,0 +1,17 @@
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = {
|
||||
command: 'df',
|
||||
description: 'Delete a file from your webserver (https://{domain}/{fileName})',
|
||||
syntax: '{PREFIX}df [fileName]',
|
||||
execute: async (_this, msg, args) => {
|
||||
if (!args.join(' ')) return msg.channel.createMessage('No arguments were given');
|
||||
const fileName = args.join(' ');
|
||||
const filesDir = `${__dirname}/../../server/uploads`;
|
||||
fs.unlink(`${filesDir}/${fileName}`, err => {
|
||||
err
|
||||
? msg.channel.createMessage(`Error deleting file: ${fileName}\n${err}`)
|
||||
: msg.channel.createMessage(`Successfully Deleted File: ${fileName}`);
|
||||
});
|
||||
},
|
||||
};
|
90
bot/commands/eval.js
Normal file
90
bot/commands/eval.js
Normal file
@ -0,0 +1,90 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* eslint-disable global-require */
|
||||
/* eslint-disable no-extend-native */
|
||||
/* eslint-disable no-eval */
|
||||
module.exports = {
|
||||
command: 'eval',
|
||||
description: 'evaluate and execute javascript',
|
||||
syntax: '{PREFIX}eval [code]',
|
||||
execute: async (_this, msg, args) => {
|
||||
String.prototype.charLimitSplit = number => {
|
||||
if (typeof number !== 'number') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
number = parseInt(number, 10);
|
||||
}
|
||||
const newSplit = [];
|
||||
if (this.length > number) {
|
||||
const splitRegex = new RegExp(`.{1,${number}}`, 'g');
|
||||
const splitStr = this.match(splitRegex);
|
||||
for (let i = 0; i < splitStr.length; i++) {
|
||||
newSplit.push(splitStr[i]);
|
||||
}
|
||||
return newSplit;
|
||||
}
|
||||
};
|
||||
const code = args.join(' ');
|
||||
async function success(input, output) {
|
||||
msg.channel.createMessage({
|
||||
embed: {
|
||||
color: 0x36393E,
|
||||
fields: [{
|
||||
name: 'Input',
|
||||
value: `\`\`\`JS\n${input}\`\`\``,
|
||||
}, {
|
||||
name: 'Output',
|
||||
value: `\`\`\`JS\n${output} | ... |\`\`\``,
|
||||
}],
|
||||
},
|
||||
});
|
||||
}
|
||||
async function error(input, output) {
|
||||
msg.channel.createMessage({
|
||||
embed: {
|
||||
color: 0x36393E,
|
||||
fields: [{
|
||||
name: 'Input',
|
||||
value: `\`\`\`JS\n${input}\`\`\``,
|
||||
}, {
|
||||
name: 'Error Output',
|
||||
value: `\`\`\`JS\n${output}\`\`\``,
|
||||
}],
|
||||
},
|
||||
});
|
||||
}
|
||||
function clean(text) {
|
||||
if (typeof (text) === 'string') {
|
||||
text = text.replace(/`/g, `\`${String.fromCharCode(8203)}`).replace(/@/g, `@${String.fromCharCode(8203)}`);
|
||||
const tokenObj = new RegExp(`${Buffer.from(_this.bot.user.id).toString('base64')}\\S+(?="|'|\`)`, 'gm');
|
||||
const tokenRaw = new RegExp(`${Buffer.from(_this.bot.user.id).toString('base64')}\\S+`, 'gm');
|
||||
if (text.match(tokenObj)) {
|
||||
text = text.replace(tokenObj, 'Token Cleaned');
|
||||
return text;
|
||||
} if (text.match(tokenRaw)) {
|
||||
text = text.replace(tokenRaw, 'Token Cleaned');
|
||||
return text;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
try {
|
||||
let evaled = eval(code);
|
||||
if (typeof evaled !== 'string') {
|
||||
evaled = require('util').inspect(evaled, {
|
||||
breakLength: Infinity,
|
||||
});
|
||||
}
|
||||
if (evaled.length > 1000) {
|
||||
const output = clean(evaled).charLimitSplit(1000);
|
||||
return success(code, output[0]);
|
||||
}
|
||||
return success(code, clean(evaled));
|
||||
} catch (err) {
|
||||
if (err.length > 1000) {
|
||||
const errorSplit = err.charLimitSplit(1000);
|
||||
return error(code, errorSplit);
|
||||
}
|
||||
return error(code, clean(err));
|
||||
}
|
||||
},
|
||||
};
|
18
bot/commands/exec.js
Normal file
18
bot/commands/exec.js
Normal file
@ -0,0 +1,18 @@
|
||||
const { exec } = require('child_process');
|
||||
|
||||
module.exports = {
|
||||
command: 'exec',
|
||||
description: 'execute terminal commands from Discord',
|
||||
syntax: '{PREFIX}exec [cmds]',
|
||||
execute: async (_this, msg, args) => {
|
||||
if (!args.join(' ')) return msg.channel.createMessage('No arguments were given');
|
||||
msg.channel.createMessage(`\`INPUT\`\n\`\`\`ini\n${args.join(' ')}\n\`\`\``);
|
||||
exec(args.join(' '), (error, stdout) => {
|
||||
if (error) {
|
||||
msg.channel.createMessage(`\`ERROR\`\n\`\`\`ini\n${error}\n\`\`\``);
|
||||
} else {
|
||||
msg.channel.createMessage(`\`OUTPUT\`\n\`\`\`ini\n${stdout}\n\`\`\``);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
12
bot/commands/help.js
Normal file
12
bot/commands/help.js
Normal file
@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
command: 'help',
|
||||
description: 'Get info on commands',
|
||||
syntax: '{PREFIX}help',
|
||||
execute: async (_this, msg) => {
|
||||
const cmds = [];
|
||||
_this.commands.map(cmd => {
|
||||
cmds.push(`[${cmd.command}]: ${cmd.syntax.replace('{PREFIX}', _this.c.prefix)} | ${cmd.description}`);
|
||||
});
|
||||
msg.channel.createMessage(`Here is a list of available commands\n\`\`\`ini\n${cmds.join('\n')}\n\`\`\``);
|
||||
},
|
||||
};
|
25
bot/commands/recentVisitors.js
Normal file
25
bot/commands/recentVisitors.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
command: 'rv',
|
||||
description: 'Displays recent visitors',
|
||||
syntax: '{PREFIX}rv',
|
||||
execute: async (_this, msg) => {
|
||||
const visitors = _this.db.get('visitors').value();
|
||||
if (visitors === undefined) {
|
||||
msg.channel.createMessage('Your site has no visitors');
|
||||
} else {
|
||||
const recent = visitors.map(e => e.date).sort().reverse();
|
||||
const visitorsCollection = [];
|
||||
let maximum;
|
||||
recent.length > 10
|
||||
? maximum = 10
|
||||
: maximum = recent.length;
|
||||
for (let i = 0; i < maximum; i++) {
|
||||
const targetData = _this.db.get('visitors').find({ date: recent[i] }).value();
|
||||
visitorsCollection.push(`[IP]: ${targetData.ip}\n[Page]: ${targetData.path}`);
|
||||
if (i + 1 >= maximum) {
|
||||
msg.channel.createMessage(`**ShareX Server Recent Visitors**\n\`\`\`ini\n${visitorsCollection.join('\n\n')}\n\`\`\``);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
19
bot/commands/rename.js
Normal file
19
bot/commands/rename.js
Normal file
@ -0,0 +1,19 @@
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = {
|
||||
command: 'rn',
|
||||
description: 'Rename an upload',
|
||||
syntax: '{PREFIX}rn [old fileName], [new file name]',
|
||||
execute: async (_this, msg, args) => {
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
const files = args.join(' ').split(/\, ?/);
|
||||
if (!files[0]) return msg.channel.createMessage('Supply a file name');
|
||||
if (!files[1]) return msg.channel.createMessage('Supply a new file name');
|
||||
const filesDir = `${__dirname}/../../server/uploads`;
|
||||
fs.rename(`${filesDir}/${files[0]}`, `${filesDir}/${files[1]}`, err => {
|
||||
err
|
||||
? msg.channel.createMessage(`Error renaming file: ${files[0]}\n${err}`)
|
||||
: msg.channel.createMessage(`Successfully Renamed File: ${files[1]}`);
|
||||
});
|
||||
},
|
||||
};
|
10
bot/commands/restart.js
Normal file
10
bot/commands/restart.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
command: 'restart',
|
||||
description: 'restart the webserver',
|
||||
syntax: '{PREFIX}restart',
|
||||
execute: async (_this, msg) => {
|
||||
msg.channel.createMessage('Restarting...').then(() => {
|
||||
process.exit();
|
||||
});
|
||||
},
|
||||
};
|
22
bot/commands/trafficfor.js
Normal file
22
bot/commands/trafficfor.js
Normal file
@ -0,0 +1,22 @@
|
||||
module.exports = {
|
||||
command: 'trafficfor',
|
||||
description: 'Find amount of traffic for a specific month',
|
||||
syntax: '{PREFIX}trafficfor [Month] [Year(optional)]',
|
||||
execute: async (_this, msg, args) => {
|
||||
if (!args.join(' ')) return msg.channel.createMessage('No arguments were given');
|
||||
const month = args[0].toLowerCase();
|
||||
let year;
|
||||
args[1]
|
||||
? year = `/${args[1]}`
|
||||
: year = `/${new Date().getFullYear()}`;
|
||||
const months = ['january', 'febuary', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
|
||||
if (!months.includes(month)) return msg.channel.createMessage('This is not a month.');
|
||||
const selectedMonth = `${months.indexOf(month) + 1}${year}`;
|
||||
const traffic = _this.db.get('trafficTotal').find({ month: selectedMonth }).value();
|
||||
if (traffic === undefined) {
|
||||
msg.channel.createMessage('There has not been any traffic for this month');
|
||||
} else {
|
||||
msg.channel.createMessage(`There have been a total of \`${traffic.total}\` views of your site this month..`);
|
||||
}
|
||||
},
|
||||
};
|
18
bot/commands/unbanIP.js
Normal file
18
bot/commands/unbanIP.js
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
command: 'unbanip',
|
||||
description: 'Unban an IP Address from your service',
|
||||
syntax: '{PREFIX}unbanip [IP_ADDRESS]',
|
||||
execute: async (_this, msg, args) => {
|
||||
if (!args.join(' ')) return msg.channel.createMessage('No arguments were given');
|
||||
const ipAddress = args.join(' ');
|
||||
const exists = _this.db.get('bans').find({ ip: ipAddress }).value();
|
||||
if (exists === undefined) {
|
||||
msg.channel.createMessage('This IP Address is not banned');
|
||||
} else {
|
||||
msg.channel.createMessage(`Removing ban for IP \`${ipAddress}\`...`);
|
||||
_this.db.get('bans')
|
||||
.remove({ ip: ipAddress })
|
||||
.write();
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user