Add automatic creation of vote message with random movies #16
|
@ -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 })
|
||||
kenobi marked this conversation as resolved
|
||||
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]
|
||||
|
||||
kenobi marked this conversation as resolved
kenobi
commented
What does the What does the `true` signify in this type?
magnetotail
commented
True means that it's a guild message afaik and understand the library True means that it's a guild message afaik and understand the library
|
||||
logger.debug(`Found messages: ${JSON.stringify(messages, null, 2)}`, { guildId: guildId, requestId })
|
||||
|
|
|
@ -41,7 +41,7 @@ export async function execute(event: GuildScheduledEvent) {
|
|||
sentMessage.react(Emotes[i])
|
||||
}
|
||||
|
||||
if(!task){
|
||||
if (!task) {
|
||||
task = schedule("0 * * * * *", () => checkForPollsToClose(event))
|
||||
}
|
||||
|
||||
|
@ -61,15 +61,15 @@ async function checkForPollsToClose(event: GuildScheduledEvent): Promise<void> {
|
|||
.filter(event => event.name.toLowerCase().includes("voting offen"))
|
||||
.map((value, _) => value)
|
||||
|
||||
if(!events || events.length <= 0) {
|
||||
if (!events || events.length <= 0) {
|
||||
logger.info("Did not find any events. Cancelling", { guildId: event.guildId, requestId })
|
||||
return
|
||||
} else if(events.length > 1) {
|
||||
} else if (events.length > 1) {
|
||||
logger.error(`More than one event found. Don't know which one is the right one :( Events: ${JSON.stringify(events, null, 2)}`, { guildId: event.guildId, requestId })
|
||||
return
|
||||
}
|
||||
const updatedEvent = events[0] //add two hours because of different timezones in discord api and Date.now()
|
||||
if(!updatedEvent.scheduledStartTimestamp) {
|
||||
if (!updatedEvent.scheduledStartTimestamp) {
|
||||
logger.error("Event does not have a scheduled start time. Cancelling", { guildId: event.guildId, requestId })
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
As long as the name is identical you can just use
{guild,requestId}
This gets translated to
{guildId:guildId, requestId:requestId}
Fixed on all occasions I found