added p/recent and p/rejoin/other fixes
This commit is contained in:
parent
963136bf74
commit
89b75481e9
12 changed files with 156 additions and 16 deletions
|
@ -30,7 +30,8 @@ export default {
|
|||
filename.endsWith(".ogg") ||
|
||||
filename.endsWith(".webm") ||
|
||||
filename.endsWith(".m4a") ||
|
||||
filename.endsWith(".mp4")
|
||||
filename.endsWith(".mp4") ||
|
||||
filename.endsWith(".midi")
|
||||
) {
|
||||
const filenameNoExtension = filename.split(".")[0];
|
||||
const files = fs.readdirSync("resources/soundboard");
|
||||
|
|
26
src/commands/recent.js
Normal file
26
src/commands/recent.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import fs from "fs";
|
||||
import * as action from "../util/discordAction.js";
|
||||
|
||||
export default {
|
||||
name: "recent",
|
||||
description: "sends most recent deleted message",
|
||||
execute(message, args) {
|
||||
try {
|
||||
const recent = fs.readFileSync(
|
||||
`./logs/deletedmessages/${message.guild.id}.log`
|
||||
);
|
||||
} catch (err) {
|
||||
action.reply(
|
||||
message,
|
||||
"pepperbot has yet to log a deleted message in this server"
|
||||
);
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
const recent = fs.readFileSync(
|
||||
`../pepperbot/logs/deletedmessages/${message.guild.id}.log`,
|
||||
"utf8"
|
||||
);
|
||||
action.sendMessage(message.channelId, recent);
|
||||
},
|
||||
};
|
20
src/commands/rejoin.js
Normal file
20
src/commands/rejoin.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { getVoiceConnection } from "@discordjs/voice";
|
||||
import * as action from "../util/discordAction.js";
|
||||
|
||||
export default {
|
||||
name: "rejoin",
|
||||
description: "Rejoin the voice channel",
|
||||
execute(message, args) {
|
||||
const connection = getVoiceConnection(message.guild.id);
|
||||
if (connection) {
|
||||
try {
|
||||
connection.rejoin();
|
||||
action.reply(message, "remade voice connection");
|
||||
} catch (err) {
|
||||
action.sendError(err);
|
||||
}
|
||||
} else {
|
||||
action.reply(message, "no active voice connection in this guild");
|
||||
}
|
||||
},
|
||||
};
|
|
@ -36,6 +36,8 @@ export default {
|
|||
webm: proposedfilename + ".webm",
|
||||
spacedm4a: proposedfilename.replaceAll(" ", "_") + ".m4a",
|
||||
m4a: proposedfilename + ".m4a",
|
||||
spacedmp4: proposedfilename.replaceAll(" ", "_") + ".mp4",
|
||||
mp4: proposedfilename + ".mp4",
|
||||
};
|
||||
for (const value of Object.values(possibleFilenames)) {
|
||||
if (files.includes(value)) {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { default as messageCreate } from "./messageCreate.js";
|
|||
import { default as messageDelete } from "./messageDelete.js";
|
||||
import { default as ready } from "./ready.js";
|
||||
import { default as interactionCreate } from "./interactionCreate.js";
|
||||
import { default as voiceStateUpdate } from "./voiceStateUpdate.js";
|
||||
|
||||
const events = {
|
||||
guildMemberAdd,
|
||||
|
@ -10,6 +11,7 @@ const events = {
|
|||
messageDelete,
|
||||
ready,
|
||||
interactionCreate,
|
||||
voiceStateUpdate,
|
||||
};
|
||||
|
||||
export default events;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { default as log } from "../util/log.js";
|
||||
import fs from "fs";
|
||||
import fsextra from "fs-extra";
|
||||
|
||||
export default function (message) {
|
||||
try {
|
||||
|
@ -9,19 +11,14 @@ export default function (message) {
|
|||
`deleted message from ${message.author.username} (${message.author}) with: "${message.content}"`,
|
||||
true
|
||||
);
|
||||
} catch {
|
||||
function sendError(message) {
|
||||
const channel = client.channels.cache.get("1148814162273763418");
|
||||
let msg;
|
||||
try {
|
||||
msg = channel.send(`**error:** ${message}`);
|
||||
} catch (err) {
|
||||
sendError(err.rawError.message);
|
||||
console.log(err);
|
||||
return undefined;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
sendError("undefined error");
|
||||
fsextra.ensureFileSync(
|
||||
`../pepperbot/logs/deletedmessages/${message.guild.id}.log`
|
||||
);
|
||||
fs.writeFileSync(
|
||||
`../pepperbot/logs/deletedmessages/${message.guild.id}.log`,
|
||||
message.content
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
|
17
src/events/voiceStateUpdate.js
Normal file
17
src/events/voiceStateUpdate.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { getVoiceConnection } from "@discordjs/voice";
|
||||
|
||||
export default async function (oldState, newState) {
|
||||
if ((oldState.channelId = getVoiceConnection(oldState.guild.id))) {
|
||||
if ((newState.channelId = undefined)) {
|
||||
let channel = await client.channels.cache.get(oldState.channelId);
|
||||
if (!channel) {
|
||||
console.log("unable to find voice channel");
|
||||
return;
|
||||
}
|
||||
memberCount = channel.members.size;
|
||||
if (MemberCount <= 1) {
|
||||
channel.leave();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,10 @@ client.on("interactionCreate", (interaction) => {
|
|||
events.interactionCreate(interaction);
|
||||
});
|
||||
|
||||
client.on("voiceStateUpdate", (oldState, newState) => {
|
||||
events.voiceStateUpdate(oldState, newState);
|
||||
});
|
||||
|
||||
register();
|
||||
|
||||
client.login(process.env.TOKEN);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue