diff options
author | Dziurwa <54191536+Dziurwa14@users.noreply.github.com> | 2023-04-05 23:01:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-05 23:01:11 +0200 |
commit | c9fd4040127970901aa73535217cf1df0be5bf50 (patch) | |
tree | f9dd26e73f3f6f7764db55e218e91b65be7012b9 /src/plugins/friendInvites.ts | |
parent | 814302e2727e1925c8c5253e5efc4de2f4de0c2b (diff) | |
download | Vencord-c9fd4040127970901aa73535217cf1df0be5bf50.tar.gz Vencord-c9fd4040127970901aa73535217cf1df0be5bf50.tar.bz2 Vencord-c9fd4040127970901aa73535217cf1df0be5bf50.zip |
Fix FriendInvites (#802)
Co-authored-by: Vendicated <vendicated@riseup.net>
Diffstat (limited to 'src/plugins/friendInvites.ts')
-rw-r--r-- | src/plugins/friendInvites.ts | 50 |
1 files changed, 36 insertions, 14 deletions
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: <t:${new Date(createInvite.expires_at).getTime() / 1000}:R> · - Max uses: \`${createInvite.max_uses}\` + discord.gg/${invite.code} · + Expires: <t:${new Date(invite.expires_at).getTime() / 1000}:R> · + 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: <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!" }); }, @@ -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." |