diff --git a/.gitignore b/.gitignore index 5d54583..0ad48d3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ src/logs node_modules/ src/commands/cbrowser.js +src/commands/cbrowser.disabled data/ logs/ transfer/ diff --git a/README.md b/README.md index 268384a..d818c0a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ clean up p/vileimagery, its horrendous **_Note:_** _versions before this were not uploaded to the repo, this is not the first version._ + 1.10 - changed all requires to imports + +--- + 1.9 - added p/eulogy and the capability for command arguments 1.9.1 - added command argument usage for sendlog (mobile support) diff --git a/package.json b/package.json index ee84441..cf0c058 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "", "main": "src/index.js", + "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/src/commands/addguildmember.js b/src/commands/addguildmember.js index cfa0636..37b29ee 100644 --- a/src/commands/addguildmember.js +++ b/src/commands/addguildmember.js @@ -1,5 +1,4 @@ -const fs = require("fs"); - +import fs from "fs"; const prefix = process.env.PREFIX; function delay(time) { @@ -10,11 +9,11 @@ function delay(time) { const whitelist = ["440163494529073152", "611625001950380032"]; -module.exports = { +export default { name: "addguildmember", description: "manually adds a guild member to the members list, whitelist required", - arguments: "none", + arguments: "member", execute(message, args) { if (whitelist.includes(message.author.id)) { if (message.author.bot) return; diff --git a/src/commands/commands.js b/src/commands/commands.js index 7320a11..548f127 100644 --- a/src/commands/commands.js +++ b/src/commands/commands.js @@ -1,27 +1,30 @@ -const { EmbedBuilder } = require("discord.js"); -const fs = require("fs"); -module.exports = { +import { EmbedBuilder } from "discord.js"; +import fs from "fs"; + +export default { name: "commands", description: "displays commands list", arguments: "none", execute(message, args) { - let text = ""; + (async () => { + let text = ""; - const commandFiles = fs - .readdirSync("src/commands/") - .filter((file) => file.endsWith(".js")); - for (const file of commandFiles) { - const command = require(`./${file}`); - text += `p/${command.name} - ${command.description} - command arguments: ${command.arguments}\n \n`; - } + const commandFiles = fs + .readdirSync("src/commands/") + .filter((file) => file.endsWith(".js")); - const embed = new EmbedBuilder(); - 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] }); + for (const file of commandFiles) { + const command = await import(`./${file}`); + text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`; + } + const embed = new EmbedBuilder(); + 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] }); + })(); }, }; diff --git a/src/commands/crash.js b/src/commands/crash.js index 5875789..f61f961 100644 --- a/src/commands/crash.js +++ b/src/commands/crash.js @@ -1,7 +1,7 @@ const whitelist = ["440163494529073152"]; -const fs = require("fs"); +import fs from "fs"; -module.exports = { +export default { name: "crash", description: "crashes the bot (throws an error), requires whitelist", arguments: "none", diff --git a/src/commands/createreactionrole.js b/src/commands/createreactionrole.js index f7d1713..24d0a54 100644 --- a/src/commands/createreactionrole.js +++ b/src/commands/createreactionrole.js @@ -1,11 +1,11 @@ -const { EmbedBuilder } = require("discord.js"); -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; +import discord from "discord.js"; +//const emojiRegex = require("emoji-regex"); +//const irregularsRegex = require("../util/irregularsRegex.js"); +//const irregulars = require("../util/irregulars.json"); +import fs from "fs"; +import { default as log } from "../util/log.js"; -const getEmojis = (message) => { +/*const getEmojis = (message) => { const { content } = message; const result = []; // Normal emojis @@ -51,13 +51,13 @@ const getEmojis = (message) => { }); } return result; -}; +};*/ let collectors = []; const whitelist = ["440163494529073152", "436321340304392222"]; -module.exports = { +export default { name: "createreactionrole", description: "creates reaction role, requires whitelist", arguments: "emoji, user", @@ -75,7 +75,7 @@ module.exports = { return; } - const embed = new EmbedBuilder(); + const embed = new discord.EmbedBuilder(); embed.setThumbnail( "https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png" diff --git a/src/commands/dmuser.js b/src/commands/dmuser.js index ce35afb..5fa48ec 100644 --- a/src/commands/dmuser.js +++ b/src/commands/dmuser.js @@ -1,4 +1,6 @@ -const log = require("../util/log.js").execute; +import { default as log } from "../util/log.js"; +import * as dotenv from "dotenv"; +dotenv.config(); const prefix = process.env.PREFIX; @@ -8,7 +10,7 @@ function delay(time) { }); } -module.exports = { +export default { name: "dmuser", description: "forces bot to dm a user something (this will ghost ping them)", arguments: "user, message", @@ -38,7 +40,7 @@ module.exports = { log( "forcesay.log", message, - __filename, + import.meta.url, `${message.author.username} (${message.author}) attempted to force bot to dm ${user} "${msg}"` ); ableToSend = false; @@ -50,7 +52,7 @@ module.exports = { log( "forcesay.log", message, - __filename, + import.meta.url, `${message.author.username} (${message.author}) forced bot to dm ${user.username} (${user}) "${msg}"` ); } diff --git a/src/commands/eulogy.js b/src/commands/eulogy.js index cbc0561..fe4fa6b 100644 --- a/src/commands/eulogy.js +++ b/src/commands/eulogy.js @@ -1,9 +1,10 @@ -const fs = require("fs"); -require("dotenv").config(); +import fs from "fs"; +import * as dotenv from "dotenv"; +dotenv.config(); const prefix = process.env.PREFIX; -module.exports = { +export default { name: "eulogy", description: "generates a eulogy", arguments: "name", diff --git a/src/commands/guildmembers.js b/src/commands/guildmembers.js index 5480d9d..2cfb759 100644 --- a/src/commands/guildmembers.js +++ b/src/commands/guildmembers.js @@ -1,4 +1,4 @@ -module.exports = { +export default { name: "guildmembers", description: "sends a file including all past guild members (may not be accurrate, is mostly manually updated) -- note: also includes allies", diff --git a/src/commands/links.js b/src/commands/links.js index 8271984..f36ad97 100644 --- a/src/commands/links.js +++ b/src/commands/links.js @@ -1,5 +1,5 @@ -const { EmbedBuilder } = require("discord.js"); -module.exports = { +import { EmbedBuilder } from "discord.js"; +export default { name: "links", description: 'posts "important" links', arguments: "none", diff --git a/src/commands/mymovie.js b/src/commands/mymovie.js index 51cc035..768b773 100644 --- a/src/commands/mymovie.js +++ b/src/commands/mymovie.js @@ -1,4 +1,4 @@ -module.exports = { +export default { name: "mymovie", description: "posts my movie", arguments: "none", diff --git a/src/commands/openpepper.js b/src/commands/openpepper.js index a633fb4..8a3cec7 100644 --- a/src/commands/openpepper.js +++ b/src/commands/openpepper.js @@ -1,4 +1,4 @@ -module.exports = { +export default { name: "openpepper", description: "posts open pepper repo", arguments: "none", diff --git a/src/commands/pepper.js b/src/commands/pepper.js index e1680c9..41ad7ad 100644 --- a/src/commands/pepper.js +++ b/src/commands/pepper.js @@ -1,7 +1,7 @@ -const { EmbedBuilder } = require("discord.js"); -const fs = require("fs"); +import { EmbedBuilder } from "discord.js"; +import fs from "fs"; -module.exports = { +export default { name: "pepper", description: "RPG (random pepper generator)", arguments: "none", diff --git a/src/commands/say.js b/src/commands/say.js index 8ba65d6..3d2a42d 100644 --- a/src/commands/say.js +++ b/src/commands/say.js @@ -1,4 +1,4 @@ -const log = require("../util/log.js").execute; +import { default as log } from "../util/log.js"; const prefix = process.env.PREFIX; @@ -8,7 +8,7 @@ function delay(time) { }); } -module.exports = { +export default { name: "say", description: "forces bot to say something", arguments: "message", @@ -25,7 +25,7 @@ module.exports = { log( "forcesay.log", message, - __filename, + import.meta.url, `${message.author.username} (${message.author}) forced bot to say "${msg}"` ); } diff --git a/src/commands/sendlog.js b/src/commands/sendlog.js index 9f30160..5599677 100644 --- a/src/commands/sendlog.js +++ b/src/commands/sendlog.js @@ -1,10 +1,7 @@ -const { Options } = require("discord.js"); -const { Collection } = require("discord.js"); -const prefix = process.env.PREFIX; const ignore = ["console.log"]; -const fs = require("fs"); +import fs from "fs"; -module.exports = { +export default { name: "sendlog", description: "sends log file (if the file is valid)", arguments: "m, mobile", diff --git a/src/commands/test.js b/src/commands/test.js index 37339b4..a9728ec 100644 --- a/src/commands/test.js +++ b/src/commands/test.js @@ -1,6 +1,4 @@ -const log = require("../util/log.js").execute; - -module.exports = { +export default { name: "test", description: "test command", arguments: "all", diff --git a/src/commands/vileimagery.js b/src/commands/vileimagery.js index eb39a80..b913342 100644 --- a/src/commands/vileimagery.js +++ b/src/commands/vileimagery.js @@ -1,8 +1,8 @@ -const { EmbedBuilder } = require("discord.js"); -const fs = require("fs"); +import { EmbedBuilder } from "discord.js"; +import fs from "fs"; const prefix = process.env.PREFIX; -module.exports = { +export default { name: "vileimagery", description: "Do NOT run.", arguments: "file name", diff --git a/src/events/guildMemberAdd.js b/src/events/guildMemberAdd.js index 44b142f..cfb479b 100644 --- a/src/events/guildMemberAdd.js +++ b/src/events/guildMemberAdd.js @@ -1,6 +1,6 @@ -const fs = require("fs"); +import fs from "fs"; -module.exports.execute = function (member, client) { +export default function (member, client) { if (member.guild.id === "1112819622505365556") { fs.appendFileSync( "../pepperbot/data/guildmembers.log", @@ -11,4 +11,4 @@ module.exports.execute = function (member, client) { `added new guild member ${member.user.username} (${member.user.id}) to members list` ); } -}; +} diff --git a/src/events/importEvents.js b/src/events/importEvents.js index e9eda69..f6fc2aa 100644 --- a/src/events/importEvents.js +++ b/src/events/importEvents.js @@ -1,6 +1,13 @@ -module.exports = { - guildMemberAdd: require("./guildMemberAdd.js").execute, - messageCreate: require("./messageCreate.js").execute, - messageDelete: require("./messageDelete.js").execute, - ready: require("./ready.js").execute, +import { default as guildMemberAdd } from "./guildMemberAdd.js"; +import { default as messageCreate } from "./messageCreate.js"; +import { default as messageDelete } from "./messageDelete.js"; +import { default as ready } from "./ready.js"; + +const events = { + guildMemberAdd, + messageCreate, + messageDelete, + ready, }; + +export default events; diff --git a/src/events/messageCreate.js b/src/events/messageCreate.js index f15c6b0..6298266 100644 --- a/src/events/messageCreate.js +++ b/src/events/messageCreate.js @@ -1,9 +1,10 @@ -require("dotenv").config(); -const log = require("../util/log.js").execute; -const fs = require("fs"); -const discord = require("discord.js"); +import * as dotenv from "dotenv"; +dotenv.config(); +import { default as log } from "../util/log.js"; +import fs from "fs"; +import discord from "discord.js"; -commands = new discord.Collection(); +let commands = new discord.Collection(); const commandFiles = fs .readdirSync("src/commands/") @@ -27,12 +28,12 @@ function parseargs(string) { const prefix = process.env.PREFIX; -module.exports.execute = function (message, client) { +export default function (message, client) { if (message.channel.type === 1) { log( "directmessages.log", message, - __filename, + import.meta.url, `direct message from ${message.author.username} (${message.author}) with: "${message.content}"` ); } @@ -50,7 +51,7 @@ module.exports.execute = function (message, client) { log( "failed.log", message, - __filename, + import.meta.url, `attempt to use invalid command: ${command} by: ${message.author.username} (${message.author})"` ); } @@ -59,10 +60,10 @@ module.exports.execute = function (message, client) { log( "commands.log", message, - __filename, + import.meta.url, `use of command: ${command} by: ${message.author.username} (\`${message.author}\`)"`, true ); commands.get(command).execute(message, args, client); } -}; +} diff --git a/src/events/messageDelete.js b/src/events/messageDelete.js index 33eb85a..3798a30 100644 --- a/src/events/messageDelete.js +++ b/src/events/messageDelete.js @@ -1,10 +1,11 @@ -const log = require("../util/log.js").execute; +import { default as log } from "../util/log.js"; -module.exports.execute = function (message) { +export default function (message) { log( "deletedmessages.log", message, - __filename, - `deleted message from ${message.author.username} (${message.author}) with: "${message.content}"` + import.meta.url, + `deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`, + true ); -}; +} diff --git a/src/events/ready.js b/src/events/ready.js index f72a850..ff9138c 100644 --- a/src/events/ready.js +++ b/src/events/ready.js @@ -1,7 +1,5 @@ -const log = require("../util/log.js").execute; - -module.exports.execute = function (client) { +export default function (client) { console.log(`${client.user.tag} is online.`); const channel = client.channels.cache.get("1148814162273763418"); channel.send("pepperbot restart complete"); -}; +} diff --git a/src/index.js b/src/index.js index 333b68e..553bfec 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,5 @@ -require("dotenv").config(); -const { Client, GatewayIntentBits, Partials } = require("discord.js"); - -const events = require("./events/importEvents.js"); +import { GatewayIntentBits, Partials, Client } from "discord.js"; +import events from "./events/importEvents.js"; const client = new Client({ intents: [ diff --git a/src/util/log.js b/src/util/log.js index e4c091a..bd0967a 100644 --- a/src/util/log.js +++ b/src/util/log.js @@ -1,6 +1,6 @@ -const fs = require("fs"); +import fs from "fs"; -module.exports.execute = function (file, message, from, msg, noconsole) { +export default function (file, message, from, msg, noconsole) { fs.appendFileSync( `../pepperbot/logs/${file}`, `AT: ${Date()} @@ -18,7 +18,7 @@ ADDITIONAL INFORMATION: ${msg} ` ); } -}; +} // TEMPLATE: // const log = require('../util/log.js').execute()