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/
|
data/
|
||||||
logs/
|
logs/
|
||||||
transfer/
|
transfer/
|
||||||
|
resources/
|
|
@ -22,6 +22,9 @@ clean up p/vileimagery, its horrendous
|
||||||
### VERSION HISTORY:
|
### VERSION HISTORY:
|
||||||
|
|
||||||
**_Note:_** _versions before this were not uploaded to the repo, this is not the first version._
|
**_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
|
1.8 - pushed README.md
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ module.exports = {
|
||||||
const msg = msgnoprefix.slice(0, 2000);
|
const msg = msgnoprefix.slice(0, 2000);
|
||||||
|
|
||||||
if (msg !== "") {
|
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`);
|
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 irregularsRegex = require("../util/irregularsRegex.js");
|
||||||
const irregulars = require("../util/irregulars.json");
|
const irregulars = require("../util/irregulars.json");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const log = require("../util/log.js").execute;
|
||||||
|
|
||||||
const getEmojis = (message) => {
|
const getEmojis = (message) => {
|
||||||
const { content } = message;
|
const { content } = message;
|
||||||
|
@ -65,29 +66,11 @@ module.exports = {
|
||||||
let emoji = emojis[0];
|
let emoji = emojis[0];
|
||||||
let role = message.mentions.roles.first();
|
let role = message.mentions.roles.first();
|
||||||
if (!role) {
|
if (!role) {
|
||||||
console.log("role variable missing");
|
log("failed.log", message, __filename, `role variable missing`);
|
||||||
fs.appendFileSync(
|
|
||||||
"../pepperbot/src/logs/failed.log",
|
|
||||||
"role variable missing" +
|
|
||||||
"from: " +
|
|
||||||
message.content +
|
|
||||||
" at " +
|
|
||||||
Date() +
|
|
||||||
"\n"
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!emoji) {
|
if (!emoji) {
|
||||||
console.log("emoji variable missing");
|
log("failed.log", message, __filename, `emoji variable missing`);
|
||||||
fs.appendFileSync(
|
|
||||||
"../pepperbot/src/logs/failed.log",
|
|
||||||
" emoji variable missing" +
|
|
||||||
"from: " +
|
|
||||||
message.content +
|
|
||||||
" at " +
|
|
||||||
Date() +
|
|
||||||
"\n"
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,16 +104,13 @@ module.exports = {
|
||||||
message.reply("UNAUTHORIZED");
|
message.reply("UNAUTHORIZED");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const scriptName = path.basename(__filename);
|
const scriptName = path.basename(__filename);
|
||||||
fs.appendFileSync(
|
log(
|
||||||
"../pepperbot/src/logs/failed.log",
|
"failed.log",
|
||||||
"non whitelisted user " +
|
message,
|
||||||
message.author.username +
|
__filename,
|
||||||
" (" +
|
`non whitelisted user ${message.author.username} (${message.author}) attempted accessing ${scriptName}`
|
||||||
message.author +
|
|
||||||
") attempted accessing " +
|
|
||||||
scriptName +
|
|
||||||
"\n"
|
|
||||||
);
|
);
|
||||||
|
fs.appendFileSync("../pepperbot/src/logs/failed.log");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ module.exports = {
|
||||||
description:
|
description:
|
||||||
"sends a file including all past guild members (may not be accurrate, is mostly manually updated) -- note: also includes allies",
|
"sends a file including all past guild members (may not be accurrate, is mostly manually updated) -- note: also includes allies",
|
||||||
execute(message, args) {
|
execute(message, args) {
|
||||||
const path = `../pepperbot/src/data/guildmembers.log`;
|
const path = `../pepperbot/data/guildmembers.log`;
|
||||||
message.channel.send({
|
message.channel.send({
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@ module.exports = {
|
||||||
name: "pepper",
|
name: "pepper",
|
||||||
description: "RPG (random pepper generator)",
|
description: "RPG (random pepper generator)",
|
||||||
execute(message, args) {
|
execute(message, args) {
|
||||||
const peppers = fs.readdirSync("../pepperbot/data/peppers");
|
const peppers = fs.readdirSync("../pepperbot/resources/peppers");
|
||||||
const maxRan = peppers.length;
|
const maxRan = peppers.length;
|
||||||
|
|
||||||
const randomnum = Math.floor(Math.random() * maxRan);
|
const randomnum = Math.floor(Math.random() * maxRan);
|
||||||
|
@ -16,7 +16,7 @@ module.exports = {
|
||||||
embed.setColor(0xff0000);
|
embed.setColor(0xff0000);
|
||||||
message.reply({
|
message.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
files: [`../pepperbot/data/peppers/${peppers[randomnum]}`],
|
files: [`../pepperbot/resources/peppers/${peppers[randomnum]}`],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ignore.includes(msgnoprefix)) return;
|
if (ignore.includes(msgnoprefix)) return;
|
||||||
const path = `../pepperbot/src/logs/${msgnoprefix}`;
|
const path = `../pepperbot/logs/${msgnoprefix}`;
|
||||||
message.channel.send({
|
message.channel.send({
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@ module.exports = {
|
||||||
);
|
);
|
||||||
const embed = new EmbedBuilder();
|
const embed = new EmbedBuilder();
|
||||||
const images = fs
|
const images = fs
|
||||||
.readdirSync("../pepperbot/data/vileimagery")
|
.readdirSync("../pepperbot/resources/vileimagery")
|
||||||
.filter((file) => file.endsWith(".png"));
|
.filter((file) => file.endsWith(".png"));
|
||||||
let file;
|
let file;
|
||||||
let lsMode = false;
|
let lsMode = false;
|
||||||
|
@ -33,7 +33,7 @@ module.exports = {
|
||||||
} else if (proposedfilename === "ls") {
|
} else if (proposedfilename === "ls") {
|
||||||
lsMode = true;
|
lsMode = true;
|
||||||
file = "ls";
|
file = "ls";
|
||||||
path = "../pepperbot/src/vileimagery/ls.txt";
|
path = "../pepperbot/resources/vileimagery/ls.txt";
|
||||||
} else {
|
} else {
|
||||||
embed.setDescription(
|
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."
|
"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) {
|
if (!lsMode) {
|
||||||
message.reply({
|
message.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
files: [`../pepperbot/src/vileimagery/${file}`],
|
files: [`../pepperbot/resources/vileimagery/${file}`],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
message.channel.send({
|
message.channel.send({
|
||||||
|
|
103
src/index.js
103
src/index.js
|
@ -1,13 +1,7 @@
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const {
|
const { Client, GatewayIntentBits, Partials } = require("discord.js");
|
||||||
Client,
|
|
||||||
Collection,
|
|
||||||
GatewayIntentBits,
|
|
||||||
Partials,
|
|
||||||
} = require("discord.js");
|
|
||||||
|
|
||||||
const log = require("./util/log.js").execute;
|
const events = require("./events/importEvents.js");
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -20,103 +14,20 @@ const client = new Client({
|
||||||
partials: [Partials.Message, Partials.Channel],
|
partials: [Partials.Message, Partials.Channel],
|
||||||
});
|
});
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.on("ready", (rclient) => {
|
||||||
|
events.ready(rclient);
|
||||||
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("guildMemberAdd", (member) => {
|
client.on("guildMemberAdd", (member) => {
|
||||||
if (member.guild.id === "1112819622505365556") {
|
events.guildMemberAdd(member);
|
||||||
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`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("messageDelete", async (message) => {
|
client.on("messageDelete", async (message) => {
|
||||||
if (message.content.startsWith(prefix)) {
|
events.messageDelete(message);
|
||||||
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}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("messageCreate", async (message) => {
|
client.on("messageCreate", async (message) => {
|
||||||
if (message.channel.type === 1) {
|
events.messageCreate(message, client);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.TOKEN);
|
client.login(process.env.TOKEN);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue