/[sudobot]/trunk/src/commands/automation/BallotCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/automation/BallotCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 55 by rakin, Mon Jul 29 17:28:24 2024 UTC revision 59 by rakin, Mon Jul 29 17:28:25 2024 UTC
# Line 5  import MessageEmbed from '../../client/M Line 5  import MessageEmbed from '../../client/M
5  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
6  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
7  import { fetchEmoji } from '../../utils/Emoji';  import { fetchEmoji } from '../../utils/Emoji';
8    import Ballot from '../../models/Ballot';
9    
10  export default class BallotCommand extends BaseCommand {  export default class BallotCommand extends BaseCommand {
11      supportsInteractions = true;      supportsInteractions = true;
# Line 73  export default class BallotCommand exten Line 74  export default class BallotCommand exten
74              ]              ]
75          });          });
76    
77          await client.db.runAsync('INSERT INTO ballots(content, author, msg_id, guild_id, date, channel_id) VALUES(?, ?, ?, ?, ?, ?)', [content, anonymous ? null : msg.member?.user.id, message.id, msg.guild!.id, new Date().toISOString(), msg.channel!.id]);          const ballot = new Ballot({
78          const ballot = await client.db.getAsync("SELECT * FROM ballots WHERE msg_id = ? AND guild_id = ? ORDER BY id DESC LIMIT 0, 1", [message.id, msg.guild!.id]);              content,
79                author: anonymous ? null : msg.member?.user.id,
80                msg_id: message.id,
81                guild_id: msg.guild!.id,
82                date: new Date(),
83                channel_id: msg.channel!.id
84            });
85    
86            await ballot.save();
87    
88            // await client.db.runAsync('INSERT INTO ballots(content, author, msg_id, guild_id, date, channel_id) VALUES(?, ?, ?, ?, ?, ?)', [content, anonymous ? null : msg.member?.user.id, message.id, msg.guild!.id, new Date().toISOString(), msg.channel!.id]);
89            // const ballot = await client.db.getAsync("SELECT * FROM ballots WHERE msg_id = ? AND guild_id = ? ORDER BY id DESC LIMIT 0, 1", [message.id, msg.guild!.id]);
90    
91          await message.react(<EmojiIdentifierResolvable> await fetchEmoji('check'));          await message.react(<EmojiIdentifierResolvable> await fetchEmoji('check'));
92          await message.react(<EmojiIdentifierResolvable> await fetchEmoji('error'));          await message.react(<EmojiIdentifierResolvable> await fetchEmoji('error'));
93    
94          await this.deferReply(msg, {          await this.deferReply(msg, {
95              content: `${(await fetchEmoji('check'))!.toString()} Your message has been delivered. The ballot ID is ${ballot.id}.`,              content: `${(await fetchEmoji('check'))!.toString()} Your message has been delivered. The ballot ID is ${ballot.get('id')}.`,
96          });          });
97      }      }
98    
# Line 99  export default class BallotCommand exten Line 111  export default class BallotCommand exten
111                    
112          try {          try {
113              const id = options.isInteraction ? options.options.getInteger('id') : options.args[0];              const id = options.isInteraction ? options.options.getInteger('id') : options.args[0];
114              const ballot = await client.db.getAsync("SELECT * FROM ballots WHERE id = ? ORDER BY id DESC LIMIT 0, 1", [id]);              //const ballot = await client.db.getAsync("SELECT * FROM ballots WHERE id = ? ORDER BY id DESC LIMIT 0, 1", [id]);
115                const ballot = (await Ballot.findOne({
116                    where: {
117                        id
118                    }
119                }))?.get();
120    
121              if (!ballot)              if (!ballot)
122                  throw new Error();                  throw new Error();

Legend:
Removed from v.55  
changed lines
  Added in v.59

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26