Change announcements
All announcements but initial will be deleted upon event end. Vote announcement will be deleted upon vote end Vote and vote end announcement now contain date and time
This commit is contained in:
parent
220f9dc8ef
commit
9420eb4366
@ -23,7 +23,11 @@ export default new Command({
|
|||||||
run: async (interaction: RunOptions) => {
|
run: async (interaction: RunOptions) => {
|
||||||
const command = interaction.interaction
|
const command = interaction.interaction
|
||||||
const requestId = uuid()
|
const requestId = uuid()
|
||||||
const guildId = command.guildId!
|
if(!command.guildId) {
|
||||||
|
logger.error("COMMAND DOES NOT HAVE A GUILD ID; CANCELLING!!!", {requestId})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const guildId = command.guildId
|
||||||
const announcementType = command.options.data.find(option => option.name.includes("typ"))
|
const announcementType = command.options.data.find(option => option.name.includes("typ"))
|
||||||
logger.info(`Got command for announcing ${announcementType?.value}!`, { guildId, requestId })
|
logger.info(`Got command for announcing ${announcementType?.value}!`, { guildId, requestId })
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { Guild, GuildScheduledEvent, GuildScheduledEventEditOptions, GuildScheduledEventSetStatusArg, GuildScheduledEventStatus, Message, MessageEditOptions, TextChannel } from 'discord.js'
|
import { Guild, GuildScheduledEvent, GuildScheduledEventEditOptions, GuildScheduledEventSetStatusArg, GuildScheduledEventStatus, Message, MessageCreateOptions, TextChannel } from 'discord.js'
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
|
import { client } from '../..'
|
||||||
import { config } from '../configuration'
|
import { config } from '../configuration'
|
||||||
import { Emotes } from '../events/guildScheduledEventCreate'
|
import { Emotes } from '../events/guildScheduledEventCreate'
|
||||||
import { logger } from '../logger'
|
import { logger } from '../logger'
|
||||||
import { Command } from '../structures/command'
|
import { Command } from '../structures/command'
|
||||||
import { RunOptions } from '../types/commandTypes'
|
import { RunOptions } from '../types/commandTypes'
|
||||||
import { client } from '../..'
|
import { format } from 'date-fns'
|
||||||
|
|
||||||
export default new Command({
|
export default new Command({
|
||||||
name: 'closepoll',
|
name: 'closepoll',
|
||||||
@ -49,43 +50,38 @@ export async function closePoll(guild: Guild, requestId: string) {
|
|||||||
|
|
||||||
logger.debug(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
|
logger.debug(`Last message: ${JSON.stringify(lastMessage, null, 2)}`, { guildId, requestId })
|
||||||
|
|
||||||
|
|
||||||
const votes = await (await getVotesByEmote(lastMessage, guildId, requestId))
|
const votes = await (await getVotesByEmote(lastMessage, guildId, requestId))
|
||||||
.sort((a, b) => b.count - a.count)
|
.sort((a, b) => b.count - a.count)
|
||||||
|
|
||||||
logger.debug(`votes: ${JSON.stringify(votes, null, 2)}`, { guildId, requestId })
|
logger.debug(`votes: ${JSON.stringify(votes, null, 2)}`, { guildId, requestId })
|
||||||
|
|
||||||
updateEvent(votes, guild!, guildId, requestId)
|
logger.info("Deleting vote message")
|
||||||
updateMessage(votes[0].movie, lastMessage, guildId, requestId)
|
await lastMessage.delete()
|
||||||
|
const event = await getEvent(guild, guild.id, requestId)
|
||||||
|
if(event) {
|
||||||
|
updateEvent(event, votes, guild!, guildId, requestId)
|
||||||
|
sendVoteClosedMessage(event, votes[0].movie, guildId, requestId)
|
||||||
|
}
|
||||||
|
|
||||||
//lastMessage.unpin() //todo: uncomment when bot has permission to pin/unpin
|
//lastMessage.unpin() //todo: uncomment when bot has permission to pin/unpin
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateMessage(movie: string, message: Message, guildId: string, requestId: string) {
|
async function sendVoteClosedMessage(event: GuildScheduledEvent, movie: string, guildId: string, requestId: string) {
|
||||||
const role = (await message.guild!.roles.fetch()).find(role => role.id === config.bot.announcement_role)
|
const date = event.scheduledStartAt ? format(event.scheduledStartAt, "dd.MM") : "Fehler, event hatte kein Datum"
|
||||||
const body = `[Abstimmung beendet] Gewonnen hat: ${movie}`
|
const time = event.scheduledStartAt ? format(event.scheduledStartAt, "HH:mm") : "Fehler, event hatte kein Datum"
|
||||||
.concat(message.content.substring("[Abstimmung]".length))
|
const body = `[Abstimmung beendet] <@&${config.bot.announcement_role}> Wir gucken ${movie} am ${date} um ${time}`
|
||||||
|
const options: MessageCreateOptions = {
|
||||||
const options: MessageEditOptions = {
|
|
||||||
content: body,
|
content: body,
|
||||||
allowedMentions: { parse: ["roles"] }
|
allowedMentions: { parse: ["roles"] }
|
||||||
}
|
}
|
||||||
logger.info("Updating message.", { guildId, requestId })
|
const announcementChannel = client.getAnnouncementChannelForGuild(guildId)
|
||||||
message.edit(options)
|
logger.info("Sending vote closed message.", { guildId, requestId })
|
||||||
|
announcementChannel.send(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateEvent(votes: Vote[], guild: Guild, guildId: string, requestId: string) {
|
async function updateEvent(voteEvent: GuildScheduledEvent, votes: Vote[], guild: Guild, guildId: string, requestId: string) {
|
||||||
logger.info(`Updating event with movie ${votes[0].movie}.`, { guildId, requestId })
|
logger.info(`Updating event with movie ${votes[0].movie}.`, { guildId, requestId })
|
||||||
const voteEvents = (await guild.scheduledEvents.fetch())
|
|
||||||
.map((value, _) => value)
|
|
||||||
.filter(event => event.name.toLowerCase().includes("voting offen"))
|
|
||||||
logger.debug(`Found events: ${JSON.stringify(voteEvents, null, 2)}`, { guildId, requestId })
|
|
||||||
|
|
||||||
if (!voteEvents || voteEvents.length <= 0) {
|
|
||||||
logger.error("Could not find vote event. Cancelling update!", { guildId, requestId })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const voteEvent: GuildScheduledEvent<GuildScheduledEventStatus> = voteEvents[0]
|
|
||||||
const options: GuildScheduledEventEditOptions<GuildScheduledEventStatus.Scheduled, GuildScheduledEventSetStatusArg<GuildScheduledEventStatus.Scheduled>> = {
|
const options: GuildScheduledEventEditOptions<GuildScheduledEventStatus.Scheduled, GuildScheduledEventSetStatusArg<GuildScheduledEventStatus.Scheduled>> = {
|
||||||
name: votes[0].movie,
|
name: votes[0].movie,
|
||||||
description: `!wp\nNummer 2: ${votes[1].movie} mit ${votes[1].count - 1} Stimmen\nNummer 3: ${votes[2].movie} mit ${votes[2].count - 1} Stimmen`
|
description: `!wp\nNummer 2: ${votes[1].movie} mit ${votes[1].count - 1} Stimmen\nNummer 3: ${votes[2].movie} mit ${votes[2].count - 1} Stimmen`
|
||||||
@ -95,6 +91,19 @@ async function updateEvent(votes: Vote[], guild: Guild, guildId: string, request
|
|||||||
voteEvent.edit(options)
|
voteEvent.edit(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getEvent(guild: Guild, guildId: string, requestId: string): Promise<GuildScheduledEvent | null> {
|
||||||
|
const voteEvents = (await guild.scheduledEvents.fetch())
|
||||||
|
.map((value, _) => value)
|
||||||
|
.filter(event => event.name.toLowerCase().includes("voting offen"))
|
||||||
|
logger.debug(`Found events: ${JSON.stringify(voteEvents, null, 2)}`, { guildId, requestId })
|
||||||
|
|
||||||
|
if (!voteEvents || voteEvents.length <= 0) {
|
||||||
|
logger.error("Could not find vote event. Cancelling update!", { guildId, requestId })
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return voteEvents[0]
|
||||||
|
}
|
||||||
|
|
||||||
type Vote = {
|
type Vote = {
|
||||||
emote: string, //todo habs nicht hinbekommen hier Emotes zu nutzen
|
emote: string, //todo habs nicht hinbekommen hier Emotes zu nutzen
|
||||||
count: number,
|
count: number,
|
||||||
|
@ -6,7 +6,7 @@ import { closePoll } from "../commands/closepoll";
|
|||||||
import { config } from "../configuration";
|
import { config } from "../configuration";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import toDate from "date-fns/fp/toDate";
|
import toDate from "date-fns/fp/toDate";
|
||||||
import { addDays, isAfter, isBefore } from "date-fns";
|
import { addDays, format, isAfter, isBefore } from "date-fns";
|
||||||
|
|
||||||
|
|
||||||
export const name = 'guildScheduledEventCreate'
|
export const name = 'guildScheduledEventCreate'
|
||||||
@ -31,7 +31,13 @@ export async function execute(event: GuildScheduledEvent) {
|
|||||||
const announcementChannel: TextChannel = client.getAnnouncementChannelForGuild(event.guildId)
|
const announcementChannel: TextChannel = client.getAnnouncementChannelForGuild(event.guildId)
|
||||||
logger.debug(`Found channel ${JSON.stringify(announcementChannel, null, 2)}`, { guildId: event.guildId, requestId })
|
logger.debug(`Found channel ${JSON.stringify(announcementChannel, null, 2)}`, { guildId: event.guildId, requestId })
|
||||||
|
|
||||||
let message = `[Abstimmung]\n<@&${config.bot.announcement_role}> Es gibt eine neue Abstimmung für die nächste Watchparty! Stimme hierunter für den nächsten Film ab!\n`
|
if(!event.scheduledStartAt) {
|
||||||
|
logger.info("EVENT DOES NOT HAVE STARTDATE; CANCELLING", {guildId: event.guildId, requestId})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const date = format(event.scheduledStartAt, "dd.MM")
|
||||||
|
const time = format(event.scheduledStartAt, "HH:mm")
|
||||||
|
let message = `[Abstimmung]\n<@&${config.bot.announcement_role}> Es gibt eine neue Abstimmung für die nächste Watchparty am ${date} um ${time}}! Stimme hierunter für den nächsten Film ab!\n`
|
||||||
|
|
||||||
for (let i = 0; i < movies.length; i++) {
|
for (let i = 0; i < movies.length; i++) {
|
||||||
message = message.concat(Emotes[i]).concat(": ").concat(movies[i].name!).concat("\n")
|
message = message.concat(Emotes[i]).concat(": ").concat(movies[i].name!).concat("\n")
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { GuildMember, GuildScheduledEvent, GuildScheduledEventStatus } from "discord.js";
|
import { GuildMember, GuildScheduledEvent, GuildScheduledEventStatus } from "discord.js";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
import { jellyfinHandler } from "../..";
|
import { client, jellyfinHandler } from "../..";
|
||||||
import { getGuildSpecificTriggerRoleId } from "../helper/roleFilter";
|
import { getGuildSpecificTriggerRoleId } from "../helper/roleFilter";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
|
import { manageAnnouncementRoles } from "../commands/announce";
|
||||||
|
|
||||||
|
|
||||||
export const name = 'guildScheduledEventUpdate'
|
export const name = 'guildScheduledEventUpdate'
|
||||||
@ -27,6 +28,8 @@ export async function execute(oldEvent: GuildScheduledEvent, newEvent: GuildSche
|
|||||||
if (newEvent.status === GuildScheduledEventStatus.Active)
|
if (newEvent.status === GuildScheduledEventStatus.Active)
|
||||||
createJFUsers(members, newEvent.name, requestId)
|
createJFUsers(members, newEvent.name, requestId)
|
||||||
else {
|
else {
|
||||||
|
const announcements = (await client.getAnnouncementChannelForGuild(newEvent.guild!.id).messages.fetch()).filter(message => !message.pinned)
|
||||||
|
announcements.forEach(message => message.delete())
|
||||||
members.forEach(member => {
|
members.forEach(member => {
|
||||||
member.createDM().then(channel => channel.send(`Die Watchparty ist vorbei, dein Account wurde wieder gelöscht. Wenn du einen permanenten Account haben möchtest, melde dich bei Samantha oder Marukus.`))
|
member.createDM().then(channel => channel.send(`Die Watchparty ist vorbei, dein Account wurde wieder gelöscht. Wenn du einen permanenten Account haben möchtest, melde dich bei Samantha oder Marukus.`))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user