3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-13 21:35:02 +00:00

More rework progress, mostly done up to ModActions

This commit is contained in:
Dark 2021-06-01 04:33:02 +02:00
parent 52839cc9f3
commit 57893e7f76
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
38 changed files with 199 additions and 241 deletions

View file

@ -1,9 +1,11 @@
export async function createOrReuseInvite(vc: VoiceChannel) {
const existingInvites = await vc.getInvites();
import { VoiceChannel } from "discord.js";
if (existingInvites.length !== 0) {
export async function createOrReuseInvite(vc: VoiceChannel) {
const existingInvites = await vc.fetchInvites();
if (existingInvites.size !== 0) {
return existingInvites[0];
} else {
return vc.createInvite(undefined);
return vc.createInvite();
}
}

View file

@ -1,18 +1,19 @@
import { GuildPluginData } from "knub";
import { LocateUserPluginType } from "../types";
import { sendErrorMessage } from "../../../pluginUtils";
import { GuildMember, TextChannel } from "discord.js";
export async function moveMember(
pluginData: GuildPluginData<LocateUserPluginType>,
toMoveID: string,
target: Member,
errorChannel: TextableChannel,
target: GuildMember,
errorChannel: TextChannel,
) {
const modMember: Member = await pluginData.client.getRESTGuildMember(pluginData.guild.id, toMoveID);
if (modMember.voiceState.channelID != null) {
const modMember: GuildMember = await pluginData.guild.members.fetch(toMoveID);
if (modMember.voice.channelID != null) {
try {
await modMember.edit({
channelID: target.voiceState.channelID,
channel: target.voice.channelID
});
} catch {
sendErrorMessage(pluginData, errorChannel, "Failed to move you. Are you in a voice channel?");

View file

@ -4,6 +4,7 @@ import { resolveMember } from "../../../utils";
import { sendWhere } from "./sendWhere";
import { moveMember } from "./moveMember";
import { TextChannel } from "discord.js";
export async function sendAlerts(pluginData: GuildPluginData<LocateUserPluginType>, userId: string) {
const triggeredAlerts = await pluginData.state.alerts.getAlertsByUserId(userId);
@ -12,7 +13,7 @@ export async function sendAlerts(pluginData: GuildPluginData<LocateUserPluginTyp
triggeredAlerts.forEach(alert => {
const prepend = `<@!${alert.requestor_id}>, an alert requested by you has triggered!\nReminder: \`${alert.body}\`\n`;
const txtChannel = pluginData.client.getChannel(alert.channel_id) as TextableChannel;
const txtChannel = pluginData.guild.channels.resolve(alert.channel_id) as TextChannel;
sendWhere(pluginData, member, txtChannel, prepend);
if (alert.active) {
moveMember(pluginData, alert.requestor_id, member, txtChannel);

View file

@ -3,19 +3,20 @@ import { createOrReuseInvite } from "./createOrReuseInvite";
import { GuildPluginData } from "knub";
import { LocateUserPluginType } from "../types";
import { sendErrorMessage } from "../../../pluginUtils";
import { GuildMember, Invite, TextChannel, VoiceChannel } from "discord.js";
export async function sendWhere(
pluginData: GuildPluginData<LocateUserPluginType>,
member: Member,
channel: TextableChannel,
member: GuildMember,
channel: TextChannel,
prepend: string,
) {
const voice = member.voiceState.channelID
? (pluginData.guild.channels.cache.get(member.voiceState.channelID) as VoiceChannel)
const voice = member.voice.channelID
? (pluginData.guild.channels.resolve(member.voice.channelID) as VoiceChannel)
: null;
if (voice == null) {
channel.createMessage(prepend + "That user is not in a channel");
channel.send(prepend + "That user is not in a channel");
} else {
let invite: Invite;
try {
@ -24,9 +25,10 @@ export async function sendWhere(
sendErrorMessage(pluginData, channel, "Cannot create an invite to that channel!");
return;
}
channel.createMessage({
content: prepend + `${member.mention} is in the following channel: \`${voice.name}\` ${getInviteLink(invite)}`,
allowedMentions: { users: true },
channel.send({
content: prepend + `<@${member.id}> is in the following channel: \`${voice.name}\` ${getInviteLink(invite)}`,
allowedMentions: { parse: ["users"] },
split: false,
});
}
}