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

View file

@ -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,14 +35,29 @@ 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!"
}); });
let invite: any;
if (uses === 1) {
const random = uuid.v4(); const random = uuid.v4();
const invite = await RestAPI.post({ const { body: { invite_suggestions } } = await RestAPI.post({
url: "/friend-finder/find-friends", url: "/friend-finder/find-friends",
body: { body: {
modified_contacts: { modified_contacts: {
@ -50,15 +65,17 @@ export default definePlugin({
}, },
phone_contact_methods_count: 1 phone_contact_methods_count: 1
} }
}).then(res => });
FriendInvites.createFriendInvite({ invite = await FriendInvites.createFriendInvite({
code: res.body.invite_suggestions[0][3], 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."
}); });
}, },

View file

@ -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",