93 lines
2.7 KiB
JavaScript
Executable File
93 lines
2.7 KiB
JavaScript
Executable File
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");
|
|
module.exports = {
|
|
name: "message",
|
|
run: async (client, msg) => {
|
|
const prefix = client.config.prefixes.find(p =>
|
|
msg.content.toLowerCase().startsWith(p)
|
|
);
|
|
|
|
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;
|
|
}
|
|
|
|
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))
|
|
);
|
|
|
|
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 (!client.cooldowns.has(cmd.name)) {
|
|
client.cooldowns.set(cmd.name, new Collection());
|
|
}
|
|
|
|
if (cmd.guildOnly && !msg.guild) return;
|
|
if (
|
|
cmd.developerOnly &&
|
|
!client.config.developers.find(devs => msg.author.id == devs.id)
|
|
)
|
|
return;
|
|
|
|
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);
|
|
}
|
|
}
|
|
};
|