diff --git a/src/commands/addblacklist.js b/src/commands/addblacklist.js new file mode 100644 index 0000000..2adb15e --- /dev/null +++ b/src/commands/addblacklist.js @@ -0,0 +1,28 @@ +import * as action from "../util/discordAction.js"; +import fs from "fs"; + +const prefix = process.env.PREFIX; +const whitelist = ["440163494529073152"]; + +export default { + name: "addblacklist", + description: "adds a blacklist", + arguments: "none", + execute(message, args) { + if (whitelist.includes(message.author.id)) { + if (message.author.bot) return; + const msgnoprefix = message.content.slice( + prefix.length + this.name.length + 1 + ); + const user = msgnoprefix.slice(0, 2000); + + if (user !== "") { + fs.appendFileSync("../pepperbot/data/blacklisted.log", user + "\n"); + action.reply( + message, + `operation completed (🤖); added ${user} to blacklisted file` + ); + } + } + }, +}; diff --git a/src/commands/randomsound.js b/src/commands/randomsound.js new file mode 100644 index 0000000..cb6f14e --- /dev/null +++ b/src/commands/randomsound.js @@ -0,0 +1,59 @@ +import { + createAudioPlayer, + createAudioResource, + getVoiceConnection, + joinVoiceChannel, +} from "@discordjs/voice"; +import fs from "fs"; +import * as action from "../util/discordAction.js"; + +export default { + name: "randomsound", + description: "plays specified sound file", + arguments: "", + execute(message, args) { + const audioPlayer = createAudioPlayer(); + const files = fs + .readdirSync("resources/soundboard") + .filter( + (file) => + file.endsWith(".wav") || + file.endsWith(".ogg") || + file.endsWith(".webm") || + file.endsWith(".mp3") || + file.endsWith(".m4a") + ); + const maxRan = files.length; + + const randomnum = Math.floor(Math.random() * maxRan); + + const audioResource = createAudioResource( + `resources/soundboard/${files[randomnum]}` + ); + + let connection = getVoiceConnection(message.guild.id); + if (!connection) { + if (message.member.voice.channel) { + let voiceState = message.member.voice; + + let connection = joinVoiceChannel({ + channelId: voiceState.channelId, + guildId: voiceState.guild.id, + adapterCreator: voiceState.guild.voiceAdapterCreator, + }); + + action.reply(message, `connected to <#${voiceState.channelId}>`); + } else { + 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; + } + } + connection = getVoiceConnection(message.guild.id); + connection.subscribe(audioPlayer); + audioPlayer.play(audioResource); + action.reply(message, `playing \`${files[randomnum]}\``); + }, +}; diff --git a/src/commands/removeblacklist.js b/src/commands/removeblacklist.js new file mode 100644 index 0000000..0a34678 --- /dev/null +++ b/src/commands/removeblacklist.js @@ -0,0 +1,42 @@ +import * as action from "../util/discordAction.js"; +import fs from "fs"; + +const whitelist = ["440163494529073152"]; +const prefix = process.env.PREFIX; + +export default { + name: "removeblacklist", + description: "removes a blacklist", + arguments: "none", + execute(message, args) { + if (whitelist.includes(message.author.id)) { + if (message.author.bot) return; + const msgnoprefix = message.content.slice( + prefix.length + this.name.length + 1 + ); + const filestring = fs.readFileSync( + "../pepperbot/data/blacklisted.log", + "utf8" + ); + const blacklists = filestring.split("\n"); + if (!blacklists.includes(msgnoprefix)) { + action.reply(message, "id is not blacklisted"); + return; + } + const index = blacklists.indexOf(msgnoprefix); + if (index > -1) { + blacklists.splice(index, 1); + } + let text = ""; + for (const file of blacklists) { + text += file + "\n"; + } + + fs.writeFileSync("../pepperbot/data/blacklisted.log", text); + + action.reply(message, `removed \`${msgnoprefix}\` from blacklist file`); + } else { + action.reply(message, "not whitelisted"); + } + }, +}; diff --git a/src/commands/sendblacklist.js b/src/commands/sendblacklist.js new file mode 100644 index 0000000..0e5c494 --- /dev/null +++ b/src/commands/sendblacklist.js @@ -0,0 +1,20 @@ +import * as action from "../util/discordAction.js"; +import fs from "fs"; + +export default { + name: "sendblacklist", + description: "sends blacklist", + arguments: "none", + execute(message, args) { + const filestring = fs.readFileSync( + "../pepperbot/data/blacklisted.log", + "utf8" + ); + const blacklists = filestring.split("\n"); + let text = ""; + for (const file of blacklists) { + text += file + "\n"; + } + action.sendMessage(message.channelId, text); + }, +};