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

@ -7,7 +7,7 @@ import { fillActiveAlertsList } from "./utils/fillAlertsList";
import { WhereCmd } from "./commands/WhereCmd";
import { FollowCmd } from "./commands/FollowCmd";
import { DeleteFollowCmd, ListFollowCmd } from "./commands/ListFollowCmd";
import { ChannelJoinAlertsEvt, ChannelLeaveAlertsEvt, ChannelSwitchAlertsEvt } from "./events/SendAlertsEvts";
import { VoiceStateUpdateAlertEvt } from "./events/SendAlertsEvts";
import { GuildBanRemoveAlertsEvt } from "./events/BanRemoveAlertsEvt";
import { trimPluginDescription } from "../../utils";
import Timeout = NodeJS.Timeout;
@ -53,9 +53,7 @@ export const LocateUserPlugin = zeppelinGuildPlugin<LocateUserPluginType>()({
// prettier-ignore
events: [
ChannelJoinAlertsEvt,
ChannelSwitchAlertsEvt,
ChannelLeaveAlertsEvt,
VoiceStateUpdateAlertEvt,
GuildBanRemoveAlertsEvt
],

View file

@ -46,7 +46,7 @@ export const FollowCmd = locateUserCmd({
sendSuccessMessage(
pluginData,
msg.channel,
`Every time ${args.member.mention} joins or switches VC in the next ${humanizeDuration(
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify and move you.\nPlease make sure to be in a voice channel, otherwise i cannot move you!`,
);
@ -54,7 +54,7 @@ export const FollowCmd = locateUserCmd({
sendSuccessMessage(
pluginData,
msg.channel,
`Every time ${args.member.mention} joins or switches VC in the next ${humanizeDuration(
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify you`,
);

View file

@ -14,6 +14,6 @@ export const WhereCmd = locateUserCmd({
},
async run({ message: msg, args, pluginData }) {
sendWhere(pluginData, args.member, msg.channel, `${msg.member.mention} | `);
sendWhere(pluginData, args.member, msg.channel, `<@${msg.member.id}> | `);
},
});

View file

@ -4,7 +4,7 @@ export const GuildBanRemoveAlertsEvt = locateUserEvt({
event: "guildBanAdd",
async listener(meta) {
const alerts = await meta.pluginData.state.alerts.getAlertsByUserId(meta.args.user.id);
const alerts = await meta.pluginData.state.alerts.getAlertsByUserId(meta.args.ban.user.id);
alerts.forEach(alert => {
meta.pluginData.state.alerts.delete(alert.id);
});

View file

@ -1,38 +1,27 @@
import { TextChannel } from "discord.js";
import { locateUserEvt } from "../types";
import { sendAlerts } from "../utils/sendAlerts";
export const ChannelJoinAlertsEvt = locateUserEvt({
event: "voiceChannelJoin",
export const VoiceStateUpdateAlertEvt = locateUserEvt({
event: "voiceStateUpdate",
async listener(meta) {
if (meta.pluginData.state.usersWithAlerts.includes(meta.args.member.id)) {
sendAlerts(meta.pluginData, meta.args.member.id);
}
},
});
const memberId = meta.args.oldState.member ? meta.args.oldState.member.id : meta.args.newState.member!.id;
export const ChannelSwitchAlertsEvt = locateUserEvt({
event: "voiceChannelSwitch",
if (meta.args.newState.channel != null) {
if (meta.pluginData.state.usersWithAlerts.includes(memberId)) {
sendAlerts(meta.pluginData, memberId);
}
} else {
const triggeredAlerts = await meta.pluginData.state.alerts.getAlertsByUserId(memberId);
const voiceChannel = meta.args.oldState.channel!;
async listener(meta) {
if (meta.pluginData.state.usersWithAlerts.includes(meta.args.member.id)) {
sendAlerts(meta.pluginData, meta.args.member.id);
}
},
});
export const ChannelLeaveAlertsEvt = locateUserEvt({
event: "voiceChannelLeave",
async listener(meta) {
const triggeredAlerts = await meta.pluginData.state.alerts.getAlertsByUserId(meta.args.member.id);
const voiceChannel = meta.args.oldChannel as VoiceChannel;
triggeredAlerts.forEach(alert => {
const txtChannel = meta.pluginData.client.getChannel(alert.channel_id) as TextableChannel;
txtChannel.createMessage(
`🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`${voiceChannel.name}\``,
triggeredAlerts.forEach(alert => {
const txtChannel = meta.pluginData.guild.channels.resolve(alert.channel_id) as TextChannel;
txtChannel.send(
`🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`<#!${voiceChannel.id}>\``,
);
});
}
},
});

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,
});
}
}