changed most discord actions to be handled by 1 script. this should cut down on errors and allow you to actually use the bot in other servers (i think)

This commit is contained in:
ayeuhugyu 2023-09-30 08:17:43 -07:00
parent c97762e84c
commit b7492c8ad0
30 changed files with 262 additions and 684 deletions

View file

@ -1,4 +1,5 @@
import fs from "fs";
import * as action from "../util/discordAction.js";
const prefix = process.env.PREFIX;
function delay(time) {
@ -20,11 +21,14 @@ export default {
const msgnoprefix = message.content.slice(
prefix.length + this.name.length + 1
);
const msg = msgnoprefix.slice(0, 2000);
const user = msgnoprefix.slice(0, 2000);
if (msg !== "") {
fs.appendFileSync("../pepperbot/data/guildmembers.log", msg + "\n");
message.reply(`operation completed (🤖); added ${msg} to members file`);
if (user !== "") {
fs.appendFileSync("../pepperbot/data/guildmembers.log", user + "\n");
action.reply(
message,
`operation completed (🤖); added ${user} to members file`
);
}
}
},

View file

@ -1,4 +1,5 @@
import fs from "fs";
import * as action from "../util/discordAction.js";
import request from "request"; // yes i know this is deprecated i will fix it later (no i won't)
function download(url, filename) {
@ -57,7 +58,8 @@ export default {
filename
);
if (success) {
message.reply(
action.reply(
message,
`downloaded your file to \`resources/soundboard/${filename
.toLowerCase()
.replaceAll(" ", "_")
@ -67,30 +69,39 @@ export default {
)}\`, if this name is different than the one you put, that's normal. all files are lowercased and "fixed."`
);
} else {
message.reply(
action.reply(
message,
"an unknown error occurred while attempting to download your file. see the console for details (id put it here but its probably too long for discord)"
);
}
} else {
message.reply(
`invalid file name! the file name either already exists, or you named it ls. don't name it ls.`
action.reply(
message,
`invalid file name! the file name either already exists, or you named it ls. don't name it ls. detected file name: \`${filename}\``
);
}
} else {
message.reply(
`invalid file name! the file name either already exists, or you named it ls. don't name it ls.`
action.reply(
message,
`invalid file name! the file name either already exists, or you named it ls. don't name it ls. detected file name: \`${filename}\``
);
}
} else {
message.reply("error has occurred; filename could not be split");
action.reply(
message,
"error has occurred; filename could not be split"
);
}
} else {
message.reply(
"invalid file extention; only `mp3`, `wav`, and `ogg` files are supported"
action.reply(
message,
`invalid file extention; only \`mp3\`, \`wav\`, and \`ogg\` files are supported. \`${
filename.split(".")[1]
}\` is not.`
);
}
} else {
message.reply("no file detected");
action.reply(message, "no file detected");
}
},
};

View file

@ -1,4 +1,5 @@
import { EmbedBuilder } from "discord.js";
import * as action from "../util/discordAction.js";
import fs from "fs";
export default {
@ -17,14 +18,11 @@ export default {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
}
const embed = new EmbedBuilder();
const embed = action.createEmbed();
embed.setTitle("PepperBot Commands");
embed.setDescription(text);
embed.setColor(0xff0000);
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
message.reply({ embeds: [embed] });
action.reply(message, { embeds: [embed] });
})();
},
};

View file

@ -1,5 +1,6 @@
const whitelist = ["440163494529073152"];
import fs from "fs";
import * as action from "../util/discordAction.js";
import { default as log } from "../util/log.js";
export default {
name: "crash",
@ -7,26 +8,17 @@ export default {
arguments: "none",
execute(message, args) {
if (whitelist.includes(message.author.id)) {
message.reply("crashing bot...");
fs.appendFileSync(
"../pepperbot/src/logs/errors.log",
action.reply(message, "crashing bot...");
log(
"errors.log",
message,
import.meta.url,
"force crashed at " + Date() + "\n"
);
throw "crash command executed";
} else {
message.reply("UNAUTHORIZED");
action.reply(message, "UNAUTHORIZED");
const path = require("path");
const scriptName = path.basename(__filename);
fs.appendFileSync(
"../pepperbot/src/logs/failed.log",
"non whitelisted user " +
message.author.username +
" (" +
message.author +
") attempted accessing " +
scriptName +
"\n"
);
}
},
};

View file

@ -1,58 +1,7 @@
import discord from "discord.js";
//const emojiRegex = require("emoji-regex");
//const irregularsRegex = require("../util/irregularsRegex.js");
//const irregulars = require("../util/irregulars.json");
import * as action from "../util/discordAction.js";
import fs from "fs";
import { default as log } from "../util/log.js";
/*const getEmojis = (message) => {
const { content } = message;
const result = [];
// Normal emojis
const normalEmojis = content.match(emojiRegex());
if (normalEmojis) {
// for (const emoji of normalEmojis) {
normalEmojis.forEach((emoji) => {
result.push(emoji);
});
}
// Text emojis e.g ♥ ✂ 🗨
const textEmojis = content.match(irregularsRegex());
if (textEmojis) {
textEmojis.forEach((emoji) => {
result.push(irregulars[emoji.trim()]);
});
}
// Guild emojis
let guildEmojis = content.match(/:[_a-zA-Z0-9]*>/g);
if (guildEmojis) {
guildEmojis = guildEmojis.map((e) => e.substring(1, e.length - 1));
guildEmojis.forEach((e) => {
try {
const guildEmoji = message.guild.emojis.get(e);
if (guildEmoji) {
result.push(guildEmoji);
}
} catch (error) {
console.log(error);
console.log("tried using guild emote lmao");
}
});
}
// Attempt to sort the results if its not null
if (result) {
const query = message.content;
result.sort((a, b) => {
const irregularA = getKeyByValue(irregulars, a);
const irregularB = getKeyByValue(irregulars, b);
const index1 = irregularA || a;
const index2 = irregularB || b;
return query.indexOf(index1) - query.indexOf(index2);
});
}
return result;
};*/
let collectors = [];
const whitelist = ["440163494529073152", "436321340304392222"];
@ -62,56 +11,49 @@ export default {
description: "creates reaction role, requires whitelist",
arguments: "emoji, user",
execute(message, args) {
if (whitelist.includes(message.author.id)) {
let emojis = getEmojis(message);
let emoji = emojis[0];
let role = message.mentions.roles.first();
if (!role) {
log("failed.log", message, __filename, `role variable missing`);
return;
(async () => {
if (whitelist.includes(message.author.id)) {
let emoji = args[0];
let role = message.mentions.roles.first();
if (!role) {
log("failed.log", message, __filename, `role variable missing`);
return;
}
if (!emoji) {
log("failed.log", message, __filename, `emoji variable missing`);
return;
}
const embed = action.createEmbed();
embed.setTitle(role.name);
embed.setDescription(
"React with " + emoji + " to recieve the " + role.name + " role."
);
const reactMessage = await action.sendMessage(message.channelId, {
embeds: [embed],
});
const collectorFilter = function (reaction) {
return true;
};
reactMessage.react(emoji);
const collector = message.createReactionCollector({
filter: collectorFilter,
});
collectors.push(collector);
collector.on("collect", (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
});
} else {
action.reply(message, "UNAUTHORIZED");
const path = require("path");
const scriptName = path.basename(__filename);
}
if (!emoji) {
log("failed.log", message, __filename, `emoji variable missing`);
return;
}
const embed = new discord.EmbedBuilder();
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
embed.setColor(0xff0000);
embed.setTitle(role.name);
embed.setDescription(
"React with " + emoji + " to recieve the " + role.name + " role."
);
message.channel.send({ embeds: [embed] }).then((m) => m.react(emoji));
const collectorFilter = function (reaction) {
return true;
};
const collector = message.createReactionCollector({
filter: collectorFilter,
});
collectors.push(collector);
collector.on("collect", (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
});
} else {
message.reply("UNAUTHORIZED");
const path = require("path");
const scriptName = path.basename(__filename);
log(
"failed.log",
message,
__filename,
`non whitelisted user ${message.author.username} (${message.author}) attempted accessing ${scriptName}`
);
fs.appendFileSync("../pepperbot/src/logs/failed.log");
}
})();
},
};

View file

@ -1,15 +1,8 @@
import { default as log } from "../util/log.js";
import * as dotenv from "dotenv";
dotenv.config();
import * as action from "../util/discordAction.js";
const prefix = process.env.PREFIX;
function delay(time) {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
}
export default {
name: "dmuser",
description: "forces bot to dm a user something (this will ghost ping them)",
@ -19,22 +12,23 @@ export default {
const guild = message.guild;
if (!user) {
return;
user = args[0];
if (!user) {
return;
}
}
const msgnoprefix = message.content.slice(
prefix.length + this.name.length + user.id.length + 4
);
console.log(typeof user);
console.log(user.username);
const msg = msgnoprefix.slice(0, 2000);
let ableToSend = true;
if (msg !== "") {
user.send(msg).catch(() => {
message.channel.send(
action.sendMessage(
message.channelId,
`${message.author}, cannot send message to ${user}, this is usually caused by them not being inside the server`
);
log(
@ -45,9 +39,7 @@ export default {
);
ableToSend = false;
});
if (message.deletable) {
message.delete();
}
action.messageDelete(message);
if (ableToSend) {
log(
"forcesay.log",

View file

@ -1,6 +1,5 @@
import fs from "fs";
import * as dotenv from "dotenv";
dotenv.config();
import * as action from "../util/discordAction.js";
const prefix = process.env.PREFIX;
@ -12,19 +11,19 @@ export default {
const msgnoprefix = message.content.slice(prefix.length + this.name.length);
const name = msgnoprefix.slice(0, 2000);
const jsonstring = fs.readFileSync("../pepperbot/data/eulogies.json");
const parsedeulogies = JSON.parse(jsonstring);
const maxRan = parsedeulogies.eulogies.length;
const parsedEulogies = JSON.parse(jsonstring);
const maxRan = parsedEulogies.eulogies.length;
const randomnum = Math.floor(Math.random() * maxRan);
const eulogy = parsedeulogies.eulogies[randomnum];
const eulogy = parsedEulogies.eulogies[randomnum];
if (name.replaceAll(" ", "") === "") {
message.reply("no name supplied");
action.reply(message, "no name supplied");
return;
}
const parsedeulogy = eulogy.replaceAll("##NAME", name);
message.reply(parsedeulogy);
const replacedEulogy = eulogy.replaceAll("##NAME", name);
action.reply(message, replacedEulogy);
},
};

View file

@ -1,8 +1,10 @@
import * as action from "../util/discordAction.js";
export default {
name: "git",
description: "posts open pepper repo",
arguments: "none",
execute(message, args) {
message.reply("https://git.reidlab.online/ayeuhugyu/PepperBot");
action.reply(message, "https://git.reidlab.online/ayeuhugyu/PepperBot");
},
};

View file

@ -1,3 +1,5 @@
import * as action from "../util/discordAction.js";
export default {
name: "guildmembers",
description:
@ -5,7 +7,7 @@ export default {
arguments: "none",
execute(message, args) {
const path = `../pepperbot/data/guildmembers.log`;
message.channel.send({
action.sendMessage(message.channelId, {
files: [
{
attachment: path,

View file

@ -1,6 +1,5 @@
import { joinVoiceChannel } from "@discordjs/voice";
import * as dotenv from "dotenv";
dotenv.config();
import * as action from "../util/discordAction.js";
const guildId = process.env.GUILD_ID;
@ -18,9 +17,9 @@ export default {
adapterCreator: voiceState.guild.voiceAdapterCreator,
});
message.reply(`connected to <#${voiceState.channelId}>`);
action.reply(message, `connected to <#${voiceState.channelId}>`);
} else {
message.reply("u aint connected to a voice channel blud 😂😂😂");
action.reply(message, "u aint connected to a voice channel blud 😂😂😂");
}
},
};

View file

@ -1,4 +1,5 @@
import { getVoiceConnection } from "@discordjs/voice";
import * as action from "../util/discordAction.js";
export default {
name: "leavevc",
@ -8,9 +9,12 @@ export default {
if (getVoiceConnection(message.guild.id)) {
const connection = getVoiceConnection(message.guild.id);
connection.destroy();
message.reply(`left voice channel <#${connection.joinConfig.channelId}>`);
action.reply(
message,
`left voice channel <#${connection.joinConfig.channelId}>`
);
} else {
message.reply("im not connected to a voice channel here mf");
action.reply(message, "im not connected to a voice channel here mf");
}
},
};

View file

@ -1,22 +1,18 @@
import { EmbedBuilder } from "discord.js";
import * as action from "../util/discordAction.js";
export default {
name: "links",
description: 'posts "important" links',
arguments: "none",
execute(message, args) {
const embed = new EmbedBuilder();
const embed = action.createEmbed();
embed.setTitle("very imphortance linkers");
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
embed.setColor(0xff0000);
embed.setDescription(`
https://reidlab.online
https://goop.network -- VERY IMPORTANT!!!!
pepper.church releasing [TIME] (never (not anytime soon))
`);
message.reply({ embeds: [embed] });
action.reply(message, { embeds: [embed] });
},
};

View file

@ -1,9 +1,12 @@
import * as action from "../util/discordAction.js";
export default {
name: "mymovie",
description: "posts my movie",
arguments: "none",
execute(message, args) {
message.reply(
action.reply(
message,
"https://cdn.discordapp.com/attachments/755150633191080073/1149158052784775219/My_Movie.mp4"
);
},

View file

@ -1,4 +1,4 @@
import { EmbedBuilder } from "discord.js";
import * as action from "../util/discordAction.js";
import fs from "fs";
export default {
@ -11,11 +11,10 @@ export default {
const randomnum = Math.floor(Math.random() * maxRan);
const embed = new EmbedBuilder();
const embed = action.createEmbed();
embed.setTitle("RANDOM PEPPER!!!");
embed.setImage(`attachment://${peppers[randomnum]}`);
embed.setColor(0xff0000);
message.reply({
action.reply(message, {
embeds: [embed],
files: [`../pepperbot/resources/peppers/${peppers[randomnum]}`],
});

View file

@ -1,13 +1,8 @@
import { default as log } from "../util/log.js";
import * as action from "../util/discordAction.js";
const prefix = process.env.PREFIX;
function delay(time) {
return new Promise((resolve) => {
setTimeout(resolve, time);
});
}
export default {
name: "say",
description: "forces bot to say something",
@ -18,10 +13,8 @@ export default {
const msg = msgnoprefix.slice(0, 2000);
if (msg !== "") {
message.channel.send(msg);
if (message.deletable) {
message.delete();
}
action.sendMessage(message.channelId, msg);
action.messageDelete(message);
log(
"forcesay.log",
message,

View file

@ -1,4 +1,5 @@
const ignore = ["console.log"];
import * as action from "../util/discordAction.js";
import fs from "fs";
export default {
@ -22,13 +23,13 @@ export default {
.readdirSync("../pepperbot/logs/")
.filter((file) => file.endsWith(".log"));
if (!logs.includes(msgnoprefix)) {
message.reply("invalid log file");
action.reply(message, "invalid log file");
return;
}
if (ignore.includes(msgnoprefix)) return;
const path = `../pepperbot/logs/${msgnoprefix}`;
if (!mobileMode) {
message.channel.send({
action.sendMessage(message.channelId, {
files: [
{
attachment: path,
@ -39,7 +40,8 @@ export default {
} else {
const filestring = fs.readFileSync(path, "utf8");
console.log(typeof filestring);
message.channel.send(
action.sendMessage(
message.channelId,
filestring.slice(filestring.length - 500, filestring.length)
);
}

View file

@ -5,8 +5,7 @@ import {
joinVoiceChannel,
} from "@discordjs/voice";
import fs from "fs";
import * as dotenv from "dotenv";
dotenv.config();
import * as action from "../util/discordAction.js";
const prefix = process.env.PREFIX;
@ -59,7 +58,8 @@ export default {
}
if (!file && !lsmode && !stopmode) {
message.reply(
action.reply(
message,
"unable to find your file in the soundboard folder put `ls` as your args to upload a file of all names. try replacing spaces with _s. you proposed: " +
proposedfilename
);
@ -78,9 +78,10 @@ export default {
adapterCreator: voiceState.guild.voiceAdapterCreator,
});
message.reply(`connected to <#${voiceState.channelId}>`);
action.reply(message, `connected to <#${voiceState.channelId}>`);
} else {
message.reply(
action.reply(
message,
"the bot is not in a voice channel so a sound cannot be played, and you are not in a voice channel so it can't auto join. IDIOT!"
);
return;
@ -90,7 +91,7 @@ export default {
connection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
} else {
message.channel.send({
action.sendMessage(message.channelId, {
files: [
{
attachment: "resources/soundboard/ls.txt",

View file

@ -1,14 +1,24 @@
import * as action from "../util/discordAction.js";
export default {
name: "test",
description: "test command",
arguments: "all",
execute(message, args) {
let text =
"command arguments test \nthis list should include all arguments you included in the command \n";
for (let i = 0; i < args.length; i++) {
text += args[i] + "\n";
}
message.reply(text);
(async () => {
action.sendMessage(message.channelId, "channel send test");
action.sendMainMessage("main message test");
action.sendError("error test");
const embed = action.createEmbed();
embed.setTitle("EMBED TITLE");
embed.setDescription("EMBED DESCRIPTION");
action.sendMessage(message.channelId, { embeds: [embed] });
const msg = await action.sendMainMessage("test");
action.messageDelete(msg);
action.reply(
message,
"discord action script test completed without errors"
);
})();
},
};

View file

@ -1,5 +1,7 @@
import { EmbedBuilder } from "discord.js";
import fs from "fs";
import * as action from "../util/discordAction.js";
const prefix = process.env.PREFIX;
export default {
@ -10,7 +12,7 @@ export default {
let proposedfilename = message.content.slice(
prefix.length + this.name.length + 1
);
const embed = new EmbedBuilder();
const embed = action.createEmbed();
const images = fs
.readdirSync("../pepperbot/resources/vileimagery")
.filter((file) => file.endsWith(".png"));
@ -49,12 +51,12 @@ export default {
}
embed.setColor(0xff0000);
if (!lsMode) {
message.reply({
action.reply(message, {
embeds: [embed],
files: [`../pepperbot/resources/vileimagery/${file}`],
});
} else {
message.channel.send({
action.sendMessage(message.channelId, {
files: [
{
attachment: path,