Fix FriendInvites (#802)
Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
parent
814302e272
commit
c9fd404012
|
@ -19,12 +19,16 @@
|
||||||
import { ApplicationCommandInputType, sendBotMessage } from "@api/Commands";
|
import { ApplicationCommandInputType, sendBotMessage } from "@api/Commands";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { findByProps } from "@webpack";
|
import { findByPropsLazy } from "@webpack";
|
||||||
|
import { RestAPI, UserStore } from "@webpack/common";
|
||||||
|
|
||||||
|
const FriendInvites = findByPropsLazy("createFriendInvite");
|
||||||
|
const uuid = findByPropsLazy("v4", "v1");
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "FriendInvites",
|
name: "FriendInvites",
|
||||||
description: "Create and manage friend invite links via slash commands (/create friend invite, /view friend invites, /revoke friend invites).",
|
description: "Create and manage friend invite links via slash commands (/create friend invite, /view friend invites, /revoke friend invites).",
|
||||||
authors: [Devs.afn],
|
authors: [Devs.afn, Devs.Dziurwa],
|
||||||
dependencies: ["CommandsAPI"],
|
dependencies: ["CommandsAPI"],
|
||||||
commands: [
|
commands: [
|
||||||
{
|
{
|
||||||
|
@ -32,14 +36,31 @@ export default definePlugin({
|
||||||
description: "Generates a friend invite link.",
|
description: "Generates a friend invite link.",
|
||||||
inputType: ApplicationCommandInputType.BOT,
|
inputType: ApplicationCommandInputType.BOT,
|
||||||
execute: async (_, ctx) => {
|
execute: async (_, ctx) => {
|
||||||
const friendInvites = findByProps("createFriendInvite");
|
if (!UserStore.getCurrentUser().phone)
|
||||||
const createInvite = await friendInvites.createFriendInvite();
|
return sendBotMessage(ctx.channel.id, {
|
||||||
|
content: "You need to have a phone number connected to your account to create a friend invite!"
|
||||||
|
});
|
||||||
|
|
||||||
return void sendBotMessage(ctx.channel.id, {
|
const random = uuid.v4();
|
||||||
|
const invite = await RestAPI.post({
|
||||||
|
url: "/friend-finder/find-friends",
|
||||||
|
body: {
|
||||||
|
modified_contacts: {
|
||||||
|
[random]: [1, "", ""]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(res =>
|
||||||
|
FriendInvites.createFriendInvite({
|
||||||
|
code: res.body.invite_suggestions[0][3],
|
||||||
|
recipient_phone_number_or_email: random
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
sendBotMessage(ctx.channel.id, {
|
||||||
content: `
|
content: `
|
||||||
discord.gg/${createInvite.code} ·
|
discord.gg/${invite.code} ·
|
||||||
Expires: <t:${new Date(createInvite.expires_at).getTime() / 1000}:R> ·
|
Expires: <t:${new Date(invite.expires_at).getTime() / 1000}:R> ·
|
||||||
Max uses: \`${createInvite.max_uses}\`
|
Max uses: \`${invite.max_uses}\`
|
||||||
`.trim().replace(/\s+/g, " ")
|
`.trim().replace(/\s+/g, " ")
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -49,15 +70,16 @@ export default definePlugin({
|
||||||
description: "View a list of all generated friend invites.",
|
description: "View a list of all generated friend invites.",
|
||||||
inputType: ApplicationCommandInputType.BOT,
|
inputType: ApplicationCommandInputType.BOT,
|
||||||
execute: async (_, ctx) => {
|
execute: async (_, ctx) => {
|
||||||
const friendInvites = findByProps("createFriendInvite");
|
const invites = await FriendInvites.getAllFriendInvites();
|
||||||
const invites = await friendInvites.getAllFriendInvites();
|
|
||||||
const friendInviteList = invites.map(i =>
|
const friendInviteList = invites.map(i =>
|
||||||
`_discord.gg/${i.code}_ ·
|
`
|
||||||
|
_discord.gg/${i.code}_ ·
|
||||||
Expires: <t:${new Date(i.expires_at).getTime() / 1000}:R> ·
|
Expires: <t:${new Date(i.expires_at).getTime() / 1000}:R> ·
|
||||||
Times used: \`${i.uses}/${i.max_uses}\``.trim().replace(/\s+/g, " ")
|
Times used: \`${i.uses}/${i.max_uses}\`
|
||||||
|
`.trim().replace(/\s+/g, " ")
|
||||||
);
|
);
|
||||||
|
|
||||||
return void sendBotMessage(ctx.channel.id, {
|
sendBotMessage(ctx.channel.id, {
|
||||||
content: friendInviteList.join("\n") || "You have no active friend invites!"
|
content: friendInviteList.join("\n") || "You have no active friend invites!"
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -67,7 +89,7 @@ export default definePlugin({
|
||||||
description: "Revokes all generated friend invites.",
|
description: "Revokes all generated friend invites.",
|
||||||
inputType: ApplicationCommandInputType.BOT,
|
inputType: ApplicationCommandInputType.BOT,
|
||||||
execute: async (_, ctx) => {
|
execute: async (_, ctx) => {
|
||||||
await findByProps("createFriendInvite").revokeFriendInvites();
|
await FriendInvites.revokeFriendInvites();
|
||||||
|
|
||||||
return void sendBotMessage(ctx.channel.id, {
|
return void sendBotMessage(ctx.channel.id, {
|
||||||
content: "All friend invites have been revoked."
|
content: "All friend invites have been revoked."
|
||||||
|
|
|
@ -241,5 +241,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
skyevg: {
|
skyevg: {
|
||||||
name: "skyevg",
|
name: "skyevg",
|
||||||
id: 1090310844283363348n
|
id: 1090310844283363348n
|
||||||
|
},
|
||||||
|
Dziurwa: {
|
||||||
|
name: "Dziurwa",
|
||||||
|
id: 787017887877169173n
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue