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; |
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 |
|
|
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(); |