Compare commits
No commits in common. "198a25d145eab98f5d9af679c3148310ed200609" and "a5eab2f7be5c6d3ac0e4d481b301f89ed72f6cd9" have entirely different histories.
198a25d145
...
a5eab2f7be
@ -1,4 +1,4 @@
|
||||
import { ApplicationCommandOptionType, Guild, GuildMember, Message, MessageCreateOptions, MessageReaction, Role, TextChannel, User } from 'discord.js'
|
||||
import { Guild, GuildMember, Message, MessageCreateOptions, MessageReaction, Role, TextChannel, User } from 'discord.js'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
import { client } from '../..'
|
||||
import { config } from '../configuration'
|
||||
@ -13,24 +13,12 @@ let task: ScheduledTask
|
||||
export default new Command({
|
||||
name: 'announce',
|
||||
description: 'Neues announcement im announcement Channel an alle senden.',
|
||||
options: [{
|
||||
name: "typ",
|
||||
type: ApplicationCommandOptionType.String,
|
||||
description:"Was für ein announcement?",
|
||||
choices: [{name: "initial", value:"initial"},{name: "votepls", value:"votepls"},{name: "cancel", value:"cancel"}],
|
||||
required: true
|
||||
}],
|
||||
options: [],
|
||||
run: async (interaction: RunOptions) => {
|
||||
const command = interaction.interaction
|
||||
const requestId = uuid()
|
||||
const guildId = command.guildId!
|
||||
const announcementType = command.options.data.find(option => option.name.includes("typ"))
|
||||
logger.info(`Got command for announcing ${announcementType?.value}!`, { guildId, requestId })
|
||||
|
||||
if(!announcementType) {
|
||||
logger.error("Did not get an announcement type!", { guildId, requestId })
|
||||
return
|
||||
}
|
||||
logger.info("Got command for announcing!", { guildId, requestId })
|
||||
|
||||
if (!isAdmin(command.member)) {
|
||||
logger.info(`Announcement was requested by ${command.member.displayName} but they are not an admin! Not sending announcement.`, { guildId, requestId })
|
||||
@ -38,13 +26,8 @@ export default new Command({
|
||||
} else {
|
||||
logger.info(`User ${command.member.displayName} seems to be admin`)
|
||||
}
|
||||
|
||||
if((<string>announcementType.value).includes("initial")) {
|
||||
sendInitialAnnouncement(guildId, requestId)
|
||||
command.followUp("Ist rausgeschickt!")
|
||||
} else {
|
||||
command.followUp(`${announcementType.value} ist aktuell noch nicht implementiert`)
|
||||
}
|
||||
sendAnnouncement(guildId, requestId)
|
||||
command.followUp("Ist rausgeschickt!")
|
||||
}
|
||||
})
|
||||
|
||||
@ -52,15 +35,15 @@ function isAdmin(member: GuildMember): boolean {
|
||||
return member.roles.cache.find((role, _) => role.id === config.bot.jf_admin_role) !== undefined
|
||||
}
|
||||
|
||||
async function sendInitialAnnouncement(guildId: string, requestId: string): Promise<void> {
|
||||
logger.info("Sending initial announcement")
|
||||
async function sendAnnouncement(guildId: string, requestId: string): Promise<void> {
|
||||
logger.info("Sending announcement")
|
||||
const announcementChannel: TextChannel = client.getAnnouncementChannelForGuild(guildId)
|
||||
|
||||
const currentPinnedAnnouncementMessages = (await announcementChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[initial]"))
|
||||
const currentPinnedAnnouncementMessages = (await announcementChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[announcement]"))
|
||||
currentPinnedAnnouncementMessages.forEach(async (message) => await message.unpin())
|
||||
currentPinnedAnnouncementMessages.forEach(message => message.delete())
|
||||
|
||||
const body = `[initial] Hey! @everyone! Hier ist der Watchparty Bot vom Hartzarett.
|
||||
const body = `[announcement] Hey! @everyone! Hier ist der Watchparty Bot vom Hartzarett.
|
||||
|
||||
Wir machen in Zukunft regelmäßig Watchparties! Falls du mitmachen möchtest, reagiere einfach auf diesen Post mit 🎫, dann bekommst du automatisch eine Rolle zugewiesen und wirst benachrichtigt sobald es in der Zukunft weitere Watchparties und Filme zum abstimmen gibt.
|
||||
|
||||
|
@ -61,16 +61,15 @@ export async function closePoll(guild: Guild, requestId: string) {
|
||||
}
|
||||
|
||||
async function updateMessage(movie: string, message: Message, guildId: string, requestId: string) {
|
||||
const role = (await message.guild!.roles.fetch()).find(role => role.id === config.bot.announcement_role)
|
||||
const body = `[Abstimmung beendet] Gewonnen hat: ${movie}`
|
||||
.concat(message.content.substring("[Abstimmung]".length))
|
||||
.concat(message.cleanContent.substring("[Abstimmung]".length))
|
||||
|
||||
const options: MessageEditOptions = {
|
||||
content: body,
|
||||
allowedMentions: { parse: ["roles"] }
|
||||
}
|
||||
logger.info("Updating message.", { guildId, requestId })
|
||||
message.edit(options)
|
||||
|
||||
}
|
||||
|
||||
async function updateEvent(votes: Vote[], guild: Guild, guildId: string, requestId: string) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { GuildScheduledEvent, Message, MessageCreateOptions, TextChannel } from "discord.js";
|
||||
import { GuildScheduledEvent, Message, TextChannel } from "discord.js";
|
||||
import { ScheduledTask, schedule } from "node-cron";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import { client, jellyfinHandler } from "../..";
|
||||
@ -30,20 +30,14 @@ export async function execute(event: GuildScheduledEvent) {
|
||||
|
||||
const announcementChannel: TextChannel = client.getAnnouncementChannelForGuild(event.guildId)
|
||||
logger.debug(`Found channel ${JSON.stringify(announcementChannel, null, 2)}`, { guildId: event.guildId, requestId })
|
||||
const role = (await event.guild!.roles.fetch()).find(role => role.id === config.bot.announcement_role)
|
||||
|
||||
let message = `[Abstimmung]\n<@&${role ? role.id : "hab die Rolle nicht gefunden"}> Es gibt eine neue Abstimmung für die nächste Watchparty! Stimme hierunter für den nächsten Film ab!\n`
|
||||
let message = "[Abstimmung]\nEs gibt eine neue Abstimmung für die nächste Watchparty! Stimme hierunter für den nächsten Film ab!\n"
|
||||
|
||||
for (let i = 0; i < movies.length; i++) {
|
||||
message = message.concat(Emotes[i]).concat(": ").concat(movies[i].name!).concat("\n")
|
||||
}
|
||||
|
||||
const options: MessageCreateOptions = {
|
||||
allowedMentions: { parse: ["roles"]},
|
||||
content: message
|
||||
}
|
||||
|
||||
const sentMessage: Message<true> = await (await announcementChannel.fetch()).send(options)
|
||||
const sentMessage: Message<true> = await (await announcementChannel.fetch()).send(message)
|
||||
|
||||
for (let i = 0; i < movies.length; i++) {
|
||||
sentMessage.react(Emotes[i])
|
||||
|
Loading…
Reference in New Issue
Block a user