/[sudobot]/branches/4.x/src/commands/information/ProfileInfoSetCommand.ts
ViewVC logotype

Contents of /branches/4.x/src/commands/information/ProfileInfoSetCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months, 1 week ago) by rakinar2
File MIME type: application/typescript
File size: 3887 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2022 OSN Inc.
5 *
6 * SudoBot is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SudoBot is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 import { CommandInteraction } from "discord.js";
21 import Client from "../../client/Client";
22 import Profile from "../../models/Profile";
23 import InteractionOptions from "../../types/InteractionOptions";
24 import BaseCommand from "../../utils/structures/BaseCommand";
25
26 export default class ProfileInfoSetCommand extends BaseCommand {
27 supportsInteractions: boolean = true;
28 supportsLegacy: boolean = false;
29
30 constructor() {
31 super("profileinfo__set", "information", []);
32 }
33
34 async run(client: Client, interaction: CommandInteraction, options: InteractionOptions): Promise<void> {
35 const age = interaction.options.getInteger('age');
36 const pronoun = interaction.options.getString('pronoun');
37 const gender = interaction.options.getString('gender');
38 const zodiac = interaction.options.getString('zodiac');
39 const continent = interaction.options.getString('continent');
40 const job = interaction.options.getString('job');
41
42 if (!age && !pronoun && !gender && !zodiac && !continent && !job) {
43 await interaction.reply({
44 content: 'Please specify at least one of the options to set.',
45 ephemeral: true
46 });
47
48 return;
49 }
50
51 if (job && job.length > 250) {
52 await interaction.reply({
53 content: 'Your job information must contain less than 250 characters!',
54 ephemeral: true
55 });
56
57 return;
58 }
59
60 await interaction.deferReply({ ephemeral: true });
61
62 const object: {
63 age?: number | null | undefined,
64 pronoun?: string | null | undefined,
65 gender?: string | null | undefined,
66 zodiac?: string | null | undefined,
67 continent?: string | null | undefined,
68 job?: string | null | undefined,
69 updatedAt: Date
70 } = {
71 updatedAt: new Date()
72 };
73
74 if (age === 0) {
75 object.age = null;
76 }
77 else if (age) {
78 object.age = age;
79 }
80
81 if (gender === 'None') {
82 object.gender = null;
83 }
84 else if (gender) {
85 object.gender = gender;
86 }
87
88 if (pronoun === 'None') {
89 object.pronoun = null;
90 }
91 else if (pronoun) {
92 object.pronoun = pronoun;
93 }
94
95 if (zodiac === 'None') {
96 object.zodiac = null;
97 }
98 else if (zodiac) {
99 object.zodiac = zodiac;
100 }
101
102 if (continent === 'None') {
103 object.continent = null;
104 }
105 else if (continent) {
106 object.continent = continent;
107 }
108
109 if (job && job.toLowerCase() === 'none') {
110 object.job = null;
111 }
112 else if (job) {
113 object.job = job;
114 }
115
116 await Profile.findOneAndUpdate({
117 user_id: interaction.user.id,
118 guild_id: interaction.guildId!
119 }, object, {
120 upsert: true
121 });
122
123 await interaction.editReply({ content: "Successfully updated profile information." });
124 }
125 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26