lots of changes

This commit is contained in:
ry 2019-11-10 09:42:09 +01:00
parent 304d0ccb96
commit f7fd3b99a4
60 changed files with 3029 additions and 878 deletions

View file

@ -1,92 +1,83 @@
const { Collection } = require("discord.js");
const { ShortLinks, SourceFynnder } = require("../utils");
let ShortLinksEnabled = true;
let SourceFynnderEnabled = true;
const { table } = require("quick.db");
const Servers = new table("servers");
const Users = new table("users");
const Backend = new table("backend");
const { Collection } = require('discord.js');
const { table } = require('quick.db');
const Servers = new table('servers');
const Users = new table('users');
const Backend = new table('backend');
module.exports = {
name: "message",
run: async (client, msg) => {
const prefix = client.config.prefixes.find(p =>
msg.content.toLowerCase().startsWith(p)
);
name: 'message',
run: async (client, msg) => {
//if (msg.author.id !== '318044130796109825') return;
if (msg.author.bot) return;
const DefaultPrefix = client.config.prefixes;
const CustomPrefix = Servers.get(msg.guild.id);
if (!CustomPrefix) {
PrefixArray = [ DefaultPrefix /* , CustomPrefix */ ].flat(Infinity);
} else {
PrefixArray = [ DefaultPrefix, CustomPrefix.prefix ].flat(Infinity);
}
let PREFIX;
let EXISTS;
for (p in PrefixArray) {
if (msg.content.startsWith(PrefixArray[p])) {
EXISTS = true;
PREFIX = p;
}
}
if (!EXISTS) return;
const args = msg.content.slice(PrefixArray[PREFIX].length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.find((c) => c.name == command || (c.aliases && c.aliases.includes(command)));
if (msg.author.bot) return;
if (msg.author.id !== "318044130796109825") return;
let Server = Servers.get(msg.guild.id);
let enabled;
if (Server === null) {
enabled = require("../utils").db.defaults.server;
} else {
enabled = Server;
}
const ctx = {
send: msg.channel.send.bind(msg.channel),
client,
msg,
args,
command: cmd,
me: msg.guild.me,
guild: msg.guild,
channel: msg.channel,
author: msg.author,
member: msg.member,
db: { users: Users, servers: Servers, backend: Backend },
utils: require('../utils'),
config: require('../config'),
isDeveloper: client.config.developers.find((dev) => msg.author.id == dev.id)
};
if (!cmd) return;
ShortLinks(enabled.Shortlinks, msg);
if (!prefix) return;
const args = msg.content.slice(prefix.length).split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.find(
c => c.name == command || (c.aliases && c.aliases.includes(command))
);
if (!client.cooldowns.has(cmd.name)) {
client.cooldowns.set(cmd.name, new Collection());
}
const ctx = {
send: msg.channel.send.bind(msg.channel),
client,
msg,
args,
command: cmd,
me: msg.guild.me,
guild: msg.guild,
channel: msg.channel,
author: msg.author,
member: msg.member,
db: { users: Users, servers: Servers, backend: Backend },
utils: require("../utils"),
isDeveloper: client.config.developers.find(id => msg.author.id == id)
};
if (!cmd) return;
if (cmd.guildOnly && !msg.guild) return;
if (cmd.nsfw && !ctx.channel.nsfw)
return ctx.send('This channel is not marked as NSFW, please mark it as such and rerun this command.');
if (cmd.developerOnly && !client.config.developers.find((dev) => msg.author.id == dev.id)) return;
if (cmd.AuthorPermissions !== 'NONE' && !ctx.member.permissions.has(cmd.AuthorPermissions))
return ctx.send(`You need \`${cmd.AuthorPermissions}\` Permission(s) to run this Command`);
const now = Date.now();
const timestamps = client.cooldowns.get(cmd.name);
const cooldownAmount = (cmd.cooldown || 1) * 1000;
if (!client.cooldowns.has(cmd.name)) {
client.cooldowns.set(cmd.name, new Collection());
}
if (timestamps.has(msg.author.id)) {
const expirationTime = timestamps.get(msg.author.id) + cooldownAmount;
if (cmd.guildOnly && !msg.guild) return;
if (
cmd.developerOnly &&
!client.config.developers.find(devs => msg.author.id == devs.id)
)
return;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return ctx.send(
`\`${cmd.name}\` has a cooldown of \`${cmd.cooldown} second${cmd.cooldown > 1
? 's'
: ''}\`, wait \`${`${Math.round(timeLeft)} second${Math.round(timeLeft) > 1
? 's'
: ''}`.replace('0 second', 'just a second longer')}\` before trying to use it again.`
);
}
} else {
timestamps.set(msg.author.id, now);
setTimeout(() => timestamps.delete(msg.author.id), cooldownAmount);
const now = Date.now();
const timestamps = client.cooldowns.get(cmd.name);
const cooldownAmount = (cmd.cooldown || 1) * 1000;
if (timestamps.has(msg.author.id)) {
const expirationTime = timestamps.get(msg.author.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return ctx.send(
`\`${cmd.name}\` has a cooldown of \`${cmd.cooldown} second${
cmd.cooldown > 1 ? "s" : ""
}\`, wait \`${`${Math.round(timeLeft)} second${
Math.round(timeLeft) > 1 ? "s" : ""
}`.replace(
"0 second",
"just a second longer"
)}\` before trying to use it again.`
);
}
} else {
timestamps.set(msg.author.id, now);
setTimeout(() => timestamps.delete(msg.author.id), cooldownAmount);
cmd
.command(ctx)
.then(() => {})
.catch(console.error);
}
}
cmd.command(ctx).then(() => {}).catch(console.error);
}
}
};

View file

@ -1,36 +1,39 @@
const p = require('phin').defaults({
method: 'POST',
parse: 'json'
method: 'POST',
parse: 'json'
});
const hastebin = require('hastebin-gen');
module.exports = {
name: 'messageReactionAdd',
run: async (client, reaction, user) => {
if (user.bot) return;
if (!client.config.developers.find(id => id == user.id)) return;
name: 'messageReactionAdd',
run: async (client, reaction, user) => {
if (user.bot) return;
if (user.id !== '318044130796109825') return;
if (reaction.emoji.name == '📥') {
let haste;
try {
if (!client.lastEval) {
await reaction.message.edit(`\`Unable to upload uncached eval results\``);
await reaction.message.reactions.removeAll();
} else {
hastebin(`${client.lastEval || `Last eval resuts weren't cached`}`, { extension: 'js' })
.then(async (h) => {
await reaction.message.edit(`<${h}>`);
await reaction.message.reactions.removeAll();
})
.catch((error) => {
// Handle error
console.error(error);
});
}
} catch (err) {
console.error(err);
}
}
if (reaction.emoji.name == '📥') {
try {
if (!client.cache.lastEval) {
await reaction.message.edit(`\`Unable to upload uncached eval results\``);
await reaction.message.reactions.removeAll();
} else {
const { body } = await p({
url: `https://hasteb.in/documents`,
data: `${client.cache.lastEval || `Last eval resuts weren't cached`}`
});
await reaction.message.edit(`<https://hasteb.in/${body.key}>`);
await reaction.message.reactions.removeAll();
}
} catch(err) {}
}
if (reaction.emoji.name == '🗑') {
try {
await reaction.message.delete();
} catch(err) {}
}
}
}
if (reaction.emoji.name == '🗑') {
try {
await reaction.message.delete();
} catch (err) {}
}
}
};

View file

@ -1,9 +1,9 @@
const { log } = require("../utils/index");
const { log } = require('../utils/index');
module.exports = {
name: "ready",
run: async client => {
log.hasStarted();
client.user.setActivity(`@${client.user.username} help to get started`);
}
name: 'ready',
run: async (client) => {
log.hasStarted();
client.user.setActivity(`nyeh`, { type: 2 });
}
};