finished linting /src/bot

This commit is contained in:
Tanner Reynolds 2019-04-16 15:51:06 -07:00
parent 8d87038318
commit 2d327d51e3
8 changed files with 117 additions and 114 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
/* eslint-disable global-require */
/* eslint-disable no-extend-native */
/* eslint-disable no-eval */

View File

@ -1,17 +1,18 @@
const { exec } = require("child_process");
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, stderr) => {
if (error) {
msg.channel.createMessage(`\`ERROR\`\n\`\`\`ini\n${error}\n\`\`\``);
} else {
msg.channel.createMessage(`\`OUTPUT\`\n\`\`\`ini\n${stdout}\n\`\`\``);
}
});
}
}
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\`\`\``);
}
});
},
};

View File

@ -1,12 +1,12 @@
module.exports = {
command:"help",
description: "Get info on commands",
syntax: "{PREFIX}help",
execute:async (_this, msg, args) => {
let cmds = [];
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\`\`\``)
}
}
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\`\`\``);
},
};

View File

@ -1,26 +1,25 @@
module.exports = {
command:"rv",
description: "Displays recent visitors",
syntax: "{PREFIX}rv",
execute:async (_this, msg, args) => {
let visitors = _this.db.get("visitors").value();
if(visitors === undefined) {
msg.channel.createMessage("Your site has no visitors")
} else {
let visitors = _this.db.get("visitors").value();
let recent = visitors.map(e => { return e.date }).sort().reverse()
let visitorsCollection = []
let maximum
recent.length > 10
? maximum = 10
: maximum = recent.length
for(i = 0; i < maximum; i++) {
let 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\`\`\``)
}
}
}
}
}
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\`\`\``);
}
}
}
},
};

View File

@ -1,17 +1,19 @@
const fs = require("fs")
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) => {
let 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")
let 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]}`);
});
}
}
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]}`);
});
},
};

View File

@ -1,10 +1,10 @@
module.exports = {
command:"restart",
description: "restart the webserver",
syntax: "{PREFIX}restart",
execute:async (_this, msg, args) => {
msg.channel.createMessage("Restarting...").then(m => {
process.exit()
})
}
}
command: 'restart',
description: 'restart the webserver',
syntax: '{PREFIX}restart',
execute: async (_this, msg) => {
msg.channel.createMessage('Restarting...').then(() => {
process.exit();
});
},
};

View File

@ -1,22 +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")
let month = args[0].toLowerCase()
let year
args[1]
? year = `/${args[1]}`
: year = `/${new Date().getFullYear()}`
let 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.")
let selectedMonth = `${months.indexOf(month) + 1}${year}`
let 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..`)
}
}
}
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..`);
}
},
};

View File

@ -1,18 +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")
let ipAddress = args.join(" ")
let 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();
}
}
}
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();
}
},
};