FriendInvites: Add picking uses (1 or 5) (#1727)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Dziurwa 2023-09-23 03:50:14 +02:00 committed by GitHub
parent 08c5d23636
commit 83bfe28fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 22 deletions

@ -1,6 +1,6 @@
/* /*
* Vencord, a modification for Discord's desktop app * Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 Vendicated and contributors * Copyright (c) 2023 Vendicated and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { ApplicationCommandInputType, sendBotMessage } from "@api/Commands"; import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, 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 { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
@ -35,30 +35,47 @@ export default definePlugin({
name: "create friend invite", name: "create friend invite",
description: "Generates a friend invite link.", description: "Generates a friend invite link.",
inputType: ApplicationCommandInputType.BOT, inputType: ApplicationCommandInputType.BOT,
execute: async (_, ctx) => { options: [{
if (!UserStore.getCurrentUser().phone) name: "Uses",
description: "How many uses?",
choices: [
{ label: "1", name: "1", value: "1" },
{ label: "5", name: "5", value: "5" }
],
required: false,
type: ApplicationCommandOptionType.INTEGER
}],
execute: async (args, ctx) => {
const uses = findOption<number>(args, "Uses", 5);
if (uses === 1 && !UserStore.getCurrentUser().phone)
return sendBotMessage(ctx.channel.id, { return sendBotMessage(ctx.channel.id, {
content: "You need to have a phone number connected to your account to create a friend invite!" content: "You need to have a phone number connected to your account to create a friend invite with 1 use!"
}); });
const random = uuid.v4(); let invite: any;
const invite = await RestAPI.post({ if (uses === 1) {
url: "/friend-finder/find-friends", const random = uuid.v4();
body: { const { body: { invite_suggestions } } = await RestAPI.post({
modified_contacts: { url: "/friend-finder/find-friends",
[random]: [1, "", ""] body: {
}, modified_contacts: {
phone_contact_methods_count: 1 [random]: [1, "", ""]
} },
}).then(res => phone_contact_methods_count: 1
FriendInvites.createFriendInvite({ }
code: res.body.invite_suggestions[0][3], });
invite = await FriendInvites.createFriendInvite({
code: invite_suggestions[0][3],
recipient_phone_number_or_email: random, recipient_phone_number_or_email: random,
contact_visibility: 1, contact_visibility: 1,
filter_visibilities: [], filter_visibilities: [],
filtered_invite_suggestions_index: 1 filtered_invite_suggestions_index: 1
}) });
); } else {
invite = await FriendInvites.createFriendInvite();
}
sendBotMessage(ctx.channel.id, { sendBotMessage(ctx.channel.id, {
content: ` content: `
@ -67,7 +84,7 @@ export default definePlugin({
Max uses: \`${invite.max_uses}\` Max uses: \`${invite.max_uses}\`
`.trim().replace(/\s+/g, " ") `.trim().replace(/\s+/g, " ")
}); });
}, }
}, },
{ {
name: "view friend invites", name: "view friend invites",
@ -95,7 +112,7 @@ export default definePlugin({
execute: async (_, ctx) => { execute: async (_, ctx) => {
await FriendInvites.revokeFriendInvites(); await FriendInvites.revokeFriendInvites();
return void sendBotMessage(ctx.channel.id, { sendBotMessage(ctx.channel.id, {
content: "All friend invites have been revoked." content: "All friend invites have been revoked."
}); });
}, },

@ -265,7 +265,7 @@ export const Devs = /* #__PURE__*/ Object.freeze({
}, },
Dziurwa: { Dziurwa: {
name: "Dziurwa", name: "Dziurwa",
id: 1034579679526526976n id: 1001086404203389018n
}, },
AutumnVN: { AutumnVN: {
name: "AutumnVN", name: "AutumnVN",