more file reorganization, moved all events from index.js to events folder in seperate scripts
This commit is contained in:
parent
943c39a0bb
commit
1b03b8ca15
9 changed files with 29 additions and 134 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ src/commands/cbrowser.js
|
|||
data/
|
||||
logs/
|
||||
transfer/
|
||||
resources/
|
|
@ -22,6 +22,9 @@ clean up p/vileimagery, its horrendous
|
|||
### VERSION HISTORY:
|
||||
|
||||
**_Note:_** _versions before this were not uploaded to the repo, this is not the first version._
|
||||
1.9 - **MAJOR CHANGE:** reorganized files some more, moved all events from index.js to seperate scripts in events folder,
|
||||
|
||||
---
|
||||
|
||||
1.8 - pushed README.md
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
const msg = msgnoprefix.slice(0, 2000);
|
||||
|
||||
if (msg !== "") {
|
||||
fs.appendFileSync("../pepperbot/src/data/guildmembers.log", msg + "\n");
|
||||
fs.appendFileSync("../pepperbot/data/guildmembers.log", msg + "\n");
|
||||
message.reply(`operation completed (🤖); added ${msg} to members file`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ const emojiRegex = require("emoji-regex");
|
|||
const irregularsRegex = require("../util/irregularsRegex.js");
|
||||
const irregulars = require("../util/irregulars.json");
|
||||
const fs = require("fs");
|
||||
const log = require("../util/log.js").execute;
|
||||
|
||||
const getEmojis = (message) => {
|
||||
const { content } = message;
|
||||
|
@ -65,29 +66,11 @@ module.exports = {
|
|||
let emoji = emojis[0];
|
||||
let role = message.mentions.roles.first();
|
||||
if (!role) {
|
||||
console.log("role variable missing");
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/logs/failed.log",
|
||||
"role variable missing" +
|
||||
"from: " +
|
||||
message.content +
|
||||
" at " +
|
||||
Date() +
|
||||
"\n"
|
||||
);
|
||||
log("failed.log", message, __filename, `role variable missing`);
|
||||
return;
|
||||
}
|
||||
if (!emoji) {
|
||||
console.log("emoji variable missing");
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/logs/failed.log",
|
||||
" emoji variable missing" +
|
||||
"from: " +
|
||||
message.content +
|
||||
" at " +
|
||||
Date() +
|
||||
"\n"
|
||||
);
|
||||
log("failed.log", message, __filename, `emoji variable missing`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -121,16 +104,13 @@ module.exports = {
|
|||
message.reply("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"
|
||||
log(
|
||||
"failed.log",
|
||||
message,
|
||||
__filename,
|
||||
`non whitelisted user ${message.author.username} (${message.author}) attempted accessing ${scriptName}`
|
||||
);
|
||||
fs.appendFileSync("../pepperbot/src/logs/failed.log");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ module.exports = {
|
|||
description:
|
||||
"sends a file including all past guild members (may not be accurrate, is mostly manually updated) -- note: also includes allies",
|
||||
execute(message, args) {
|
||||
const path = `../pepperbot/src/data/guildmembers.log`;
|
||||
const path = `../pepperbot/data/guildmembers.log`;
|
||||
message.channel.send({
|
||||
files: [
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@ module.exports = {
|
|||
name: "pepper",
|
||||
description: "RPG (random pepper generator)",
|
||||
execute(message, args) {
|
||||
const peppers = fs.readdirSync("../pepperbot/data/peppers");
|
||||
const peppers = fs.readdirSync("../pepperbot/resources/peppers");
|
||||
const maxRan = peppers.length;
|
||||
|
||||
const randomnum = Math.floor(Math.random() * maxRan);
|
||||
|
@ -16,7 +16,7 @@ module.exports = {
|
|||
embed.setColor(0xff0000);
|
||||
message.reply({
|
||||
embeds: [embed],
|
||||
files: [`../pepperbot/data/peppers/${peppers[randomnum]}`],
|
||||
files: [`../pepperbot/resources/peppers/${peppers[randomnum]}`],
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ module.exports = {
|
|||
return;
|
||||
}
|
||||
if (ignore.includes(msgnoprefix)) return;
|
||||
const path = `../pepperbot/src/logs/${msgnoprefix}`;
|
||||
const path = `../pepperbot/logs/${msgnoprefix}`;
|
||||
message.channel.send({
|
||||
files: [
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = {
|
|||
);
|
||||
const embed = new EmbedBuilder();
|
||||
const images = fs
|
||||
.readdirSync("../pepperbot/data/vileimagery")
|
||||
.readdirSync("../pepperbot/resources/vileimagery")
|
||||
.filter((file) => file.endsWith(".png"));
|
||||
let file;
|
||||
let lsMode = false;
|
||||
|
@ -33,7 +33,7 @@ module.exports = {
|
|||
} else if (proposedfilename === "ls") {
|
||||
lsMode = true;
|
||||
file = "ls";
|
||||
path = "../pepperbot/src/vileimagery/ls.txt";
|
||||
path = "../pepperbot/resources/vileimagery/ls.txt";
|
||||
} else {
|
||||
embed.setDescription(
|
||||
"unable to find your file in the vile imagery folder, instead it has been replaced with a random one. put `ls` as your args to upload a file of all names. try replacing spaces with _s."
|
||||
|
@ -51,7 +51,7 @@ module.exports = {
|
|||
if (!lsMode) {
|
||||
message.reply({
|
||||
embeds: [embed],
|
||||
files: [`../pepperbot/src/vileimagery/${file}`],
|
||||
files: [`../pepperbot/resources/vileimagery/${file}`],
|
||||
});
|
||||
} else {
|
||||
message.channel.send({
|
||||
|
|
103
src/index.js
103
src/index.js
|
@ -1,13 +1,7 @@
|
|||
require("dotenv").config();
|
||||
const {
|
||||
Client,
|
||||
Collection,
|
||||
GatewayIntentBits,
|
||||
Partials,
|
||||
} = require("discord.js");
|
||||
const { Client, GatewayIntentBits, Partials } = require("discord.js");
|
||||
|
||||
const log = require("./util/log.js").execute;
|
||||
const fs = require("fs");
|
||||
const events = require("./events/importEvents.js");
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
|
@ -20,103 +14,20 @@ const client = new Client({
|
|||
partials: [Partials.Message, Partials.Channel],
|
||||
});
|
||||
|
||||
client.commands = new Collection();
|
||||
|
||||
const commandFiles = fs
|
||||
.readdirSync("src/commands/")
|
||||
.filter((file) => file.endsWith(".js"));
|
||||
for (const file of commandFiles) {
|
||||
(async () => {
|
||||
const command = await import(`./commands/${file}`);
|
||||
client.commands.set(command.default.name, command.default);
|
||||
})();
|
||||
}
|
||||
|
||||
const prefix = process.env.PREFIX;
|
||||
|
||||
client.on("ready", (c) => {
|
||||
console.log(`${c.user.tag} is online.`);
|
||||
const channel = client.channels.cache.get("1148814162273763418");
|
||||
channel.send("pepperbot restart complete");
|
||||
client.on("ready", (rclient) => {
|
||||
events.ready(rclient);
|
||||
});
|
||||
|
||||
client.on("guildMemberAdd", (member) => {
|
||||
if (member.guild.id === "1112819622505365556") {
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/data/guildmembers.log",
|
||||
member.user.username + ` -- added by bot: ${Date()} \n`
|
||||
);
|
||||
const channel = client.channels.cache.get("1148814162273763418");
|
||||
channel.send(
|
||||
`added new guild member ${member.user.username} (${member.user.id}) to members list`
|
||||
);
|
||||
}
|
||||
events.guildMemberAdd(member);
|
||||
});
|
||||
|
||||
client.on("messageDelete", async (message) => {
|
||||
if (message.content.startsWith(prefix)) {
|
||||
const args = message.content.slice(prefix.length).split(/ +/);
|
||||
const command = args.shift().toLowerCase();
|
||||
if (!client.commands.has(command)) {
|
||||
log(
|
||||
"deletedmessages.log",
|
||||
message,
|
||||
__filename,
|
||||
`deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log(
|
||||
"deletedmessages.log",
|
||||
message,
|
||||
__filename,
|
||||
`deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`
|
||||
);
|
||||
}
|
||||
events.messageDelete(message);
|
||||
});
|
||||
|
||||
client.on("messageCreate", async (message) => {
|
||||
if (message.channel.type === 1) {
|
||||
log(
|
||||
"directmessages.log",
|
||||
message,
|
||||
__filename,
|
||||
`direct message from ${message.author.username} (${message.author}) with: "${message.content}"`
|
||||
);
|
||||
}
|
||||
if (!message.content.startsWith(prefix)) return;
|
||||
const args = message.content.slice(prefix.length).split(/ +/);
|
||||
const command = args.shift().toLowerCase();
|
||||
|
||||
/*if (message.channelId !== "1148814162273763418") {
|
||||
let text = "commands only work in <#1148814162273763418>";
|
||||
if (!client.commands.has(command)) {
|
||||
text += ", also thats not a command lmao";
|
||||
}
|
||||
message.reply(text);
|
||||
return;
|
||||
}*/
|
||||
|
||||
if (!client.commands.has(command)) {
|
||||
message.reply("idiot thats not a command");
|
||||
log(
|
||||
"failed.log",
|
||||
message,
|
||||
__filename,
|
||||
`attempt to use invalid command: ${command} by: ${message.author.username} (${message.author})"`
|
||||
);
|
||||
}
|
||||
|
||||
if (client.commands.get(command)) {
|
||||
log(
|
||||
"commands.log",
|
||||
message,
|
||||
__filename,
|
||||
`use of command: ${command} by: ${message.author.username} (${message.author})"`,
|
||||
true
|
||||
);
|
||||
client.commands.get(command).execute(message, args, client);
|
||||
}
|
||||
events.messageCreate(message, client);
|
||||
});
|
||||
|
||||
client.login(process.env.TOKEN);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue