minor resilience improvement and formatting
in closepoll.ts was an unsafe arrays usage without checking the bounds
This commit is contained in:
parent
0d5c3d30a9
commit
1ee55f995c
@ -29,9 +29,15 @@ export default new Command({
|
||||
export async function closePoll(guild: Guild, requestId: string) {
|
||||
const guildId = guild.id
|
||||
logger.info("stopping poll", { guildId: guildId, requestId })
|
||||
const announcementChannel: TextChannel = <TextChannel>(await guild.channels.fetch())
|
||||
const channels: TextChannel[] = <TextChannel[]><unknown>(await guild.channels.fetch())
|
||||
?.filter(channel => channel!.id === config.bot.announcement_channel_id)
|
||||
.map((value, _) => value)[0] //todo: needs to be done less sketchy
|
||||
.map((value, _) => value)
|
||||
|
||||
if(!channels || channels.length != 1) {
|
||||
logger.error(`Could not find announcement channel. Found ${channels}`)
|
||||
}
|
||||
|
||||
const announcementChannel = channels[0]
|
||||
|
||||
const messages: Message<true>[] = (await announcementChannel.messages.fetch()) //todo: fetch only pinned messages
|
||||
.map((value, _) => value)
|
||||
@ -43,7 +49,6 @@ export async function closePoll(guild: Guild, requestId: string) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const lastMessage: Message<true> = messages[0]
|
||||
|
||||
logger.debug(`Found messages: ${JSON.stringify(messages, null, 2)}`, { guildId: guildId, requestId })
|
||||
|
Loading…
Reference in New Issue
Block a user