Merge pull request #2 from Neko-Life/Rina

refactor functions
This commit is contained in:
Neko Life 2021-05-17 03:06:38 +00:00 committed by GitHub
commit 7e5b228455
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const commando = require("@iceprod/discord.js-commando"); const commando = require("@iceprod/discord.js-commando");
const { ranLog, errLog, trySend, sentAdCheck, tryReact } = require("../../resources/functions"); const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions");
module.exports = class send extends commando.Command { module.exports = class send extends commando.Command {
constructor(client) { constructor(client) {
@ -9,36 +9,37 @@ module.exports = class send extends commando.Command {
memberName: "send", memberName: "send",
group: "utility", group: "utility",
description: "Send message to designated channel.", description: "Send message to designated channel.",
userPermissions:["MANAGE_MESSAGES"] guildOnly:true
}); });
} }
async run(msg, args ) { async run(msg, args ) {
const comarg = args.trim().split(/ +/); const comarg = args.trim().split(/ +/);
const bot = this.client;
let at = comarg[0]; let at = comarg[0];
if (!comarg[0]) { if (!comarg[0]) {
return trySend(this.client, msg, 'Where?!?'); return trySend(this.client, msg, 'Where?!?');
} }
if (comarg[0].startsWith('<#') && comarg[0].endsWith('>')) { const search = cleanMentionID(comarg[0]),
at = comarg[0].slice(2, -1); channel = findChannelRegEx(msg, search)[0],
} sendTheMes = args.slice(comarg[0].length).trim();
const channel = bot.channels.cache.get(at);
const sendTheMes = args.slice(comarg[0].length).trim();
if (!channel) { if (!channel) {
return trySend(this.client, msg, "Give me the right `channel_[mention, ID]` bruh"); return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>");
} else {
if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES")) {
return trySend(this.client, msg, "No <:cathmmLife:772716381874946068>");
}
} }
try { try {
if (sendTheMes.length === 0) { if (sendTheMes.length === 0) {
return trySend(this.client, at, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`); return trySend(this.client, channel, `<@!${msg.author.id}> If you wanna send nothin then why you even typed that <:bruhLife:798789686242967554>`);
} }
const sendThis = {content:sendTheMes, disableMentions:"all"}; const sendThis = {content:sendTheMes, disableMentions:"all"};
if (msg.member?.hasPermission("ADMINISTRATOR")) { if (msg.member?.hasPermission("MENTION_EVERYONE")) {
sendThis.disableMentions = "none"; sendThis.disableMentions = "none";
} }
const send = await trySend(this.client, channel, sendThis); const send = await trySend(this.client, channel, sendThis);
sentAdCheck(send); sentAdCheck(send);
const filter = () => true; const filter = () => true,
const collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true}); collector = send.createReactionCollector(filter, {time: 15*6*1000, dispose:true});
collector.on('collect', r => { collector.on('collect', r => {
try { try {
msg.react(r.emoji); msg.react(r.emoji);