diff --git a/src/plugins/friendInvites.ts b/src/plugins/friendInvites.ts index 2ad47d9..970994a 100644 --- a/src/plugins/friendInvites.ts +++ b/src/plugins/friendInvites.ts @@ -19,12 +19,16 @@ import { ApplicationCommandInputType, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; 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({ name: "FriendInvites", 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"], commands: [ { @@ -32,14 +36,31 @@ export default definePlugin({ description: "Generates a friend invite link.", inputType: ApplicationCommandInputType.BOT, execute: async (_, ctx) => { - const friendInvites = findByProps("createFriendInvite"); - const createInvite = await friendInvites.createFriendInvite(); + if (!UserStore.getCurrentUser().phone) + 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: ` - discord.gg/${createInvite.code} · - Expires: · - Max uses: \`${createInvite.max_uses}\` + discord.gg/${invite.code} · + Expires: · + Max uses: \`${invite.max_uses}\` `.trim().replace(/\s+/g, " ") }); }, @@ -49,15 +70,16 @@ export default definePlugin({ description: "View a list of all generated friend invites.", inputType: ApplicationCommandInputType.BOT, execute: async (_, ctx) => { - const friendInvites = findByProps("createFriendInvite"); - const invites = await friendInvites.getAllFriendInvites(); + const invites = await FriendInvites.getAllFriendInvites(); const friendInviteList = invites.map(i => - `_discord.gg/${i.code}_ · + ` + _discord.gg/${i.code}_ · Expires: · - 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!" }); }, @@ -67,7 +89,7 @@ export default definePlugin({ description: "Revokes all generated friend invites.", inputType: ApplicationCommandInputType.BOT, execute: async (_, ctx) => { - await findByProps("createFriendInvite").revokeFriendInvites(); + await FriendInvites.revokeFriendInvites(); return void sendBotMessage(ctx.channel.id, { content: "All friend invites have been revoked." diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 7054db2..6814fc7 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -241,5 +241,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({ skyevg: { name: "skyevg", id: 1090310844283363348n + }, + Dziurwa: { + name: "Dziurwa", + id: 787017887877169173n } });