add daily #reminder channel clearing
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
FROM node:latest
|
||||
FROM node:23
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "src/index.js"]
|
||||
CMD ["npm", "run", "prod", "src/index.js"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { Client, GatewayIntentBits, Partials, Routes, PermissionFlagsBits, PermissionsBitField, ChannelFlags, ChannelManager, ChannelFlagsBitField, ChannelType } = require('discord.js')
|
||||
const { Client, GatewayIntentBits, Partials, Routes, PermissionFlagsBits, PermissionsBitField, ChannelFlags, ChannelManager, ChannelFlagsBitField, ChannelType, Colors } = require('discord.js')
|
||||
require('dotenv').config()
|
||||
const { REST } = require('@discordjs/rest')
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders')
|
||||
@@ -37,8 +37,6 @@ const { startEventCheckCron } = require('../tasks/eventReminder')
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN)
|
||||
|
||||
let server = null
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
@@ -46,6 +44,7 @@ const client = new Client({
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.GuildMessageReactions,
|
||||
|
||||
],
|
||||
partials: [
|
||||
Partials.Channel,
|
||||
@@ -130,26 +129,28 @@ client.on('interactionCreate', async interaction => {
|
||||
} case 'static-create': {
|
||||
const static_name = interaction.options.getString('name')
|
||||
const static_size = interaction.options.getString('size')
|
||||
let static_members = [interaction.user.username]
|
||||
const member_string = interaction.options.getString('members')
|
||||
let static_members = [interaction.user]
|
||||
|
||||
try {
|
||||
const static_role = await interaction.guild.roles.create({
|
||||
name: static_name,
|
||||
color: 'BLUE',
|
||||
color: Colors.Blue,
|
||||
})
|
||||
|
||||
interaction.member.roles.add(static_role)
|
||||
|
||||
for (const username of (interaction.options.getString('members')).split(',').map(name => name.trim())) {
|
||||
const member = interaction.guild.members.cache.find(member => member.user.username === username)
|
||||
if (member_string) {
|
||||
for (const username of member_string.split(',').map(name => name.trim())) {
|
||||
const member = (await interaction.guild.members.fetch()).find(member => member.user.username === username.toLowerCase())
|
||||
|
||||
if (member) {
|
||||
static_members.push(member)
|
||||
member.roles.add(static_role)
|
||||
} else
|
||||
console.log(`WARNING: Creating static: ${static_name} member named ${username} not found`)
|
||||
if (member) {
|
||||
static_members.push(member.user)
|
||||
member.roles.add(static_role)
|
||||
} else
|
||||
console.log(`WARNING: Creating static: ${static_name} member named ${username} not found`)
|
||||
}
|
||||
}
|
||||
|
||||
let category = interaction.guild.channels.cache.find(channel => channel.name === 'Statics' && channel.type === ChannelType.GuildCategory)
|
||||
|
||||
if (!category) {
|
||||
@@ -164,11 +165,11 @@ client.on('interactionCreate', async interaction => {
|
||||
parent: category.id,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: interaction.guild.id, // @everyone role
|
||||
deny: [PermissionsBitField.Flags.ViewChannel] // Deny view for everyone
|
||||
id: interaction.guild.id,
|
||||
deny: [PermissionsBitField.Flags.ViewChannel]
|
||||
},
|
||||
{
|
||||
id: static_role.id, // Allow view for the static role
|
||||
id: static_role.id,
|
||||
allow: [PermissionsBitField.Flags.ViewChannel],
|
||||
}
|
||||
]
|
||||
@@ -180,17 +181,16 @@ client.on('interactionCreate', async interaction => {
|
||||
parent: category.id,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
id: interaction.guild.id, // @everyone role
|
||||
deny: [PermissionsBitField.Flags.ViewChannel] // Deny view for everyone
|
||||
id: interaction.guild.id,
|
||||
deny: [PermissionsBitField.Flags.ViewChannel]
|
||||
},
|
||||
{
|
||||
id: static_role.id, // Allow view for the static role
|
||||
id: static_role.id,
|
||||
allow: [PermissionsBitField.Flags.ViewChannel],
|
||||
}
|
||||
],
|
||||
})
|
||||
|
||||
const res = handleStaticAdd(static_name, static_members[0], static_members, static_size, static_role, static_text_channel, static_voice_channel)
|
||||
const res = handleStaticAdd(static_name, static_members[0].username, static_members, static_size, static_role.id, static_text_channel.id, static_voice_channel.id)
|
||||
|
||||
if (res) {
|
||||
interaction.reply({
|
||||
@@ -204,6 +204,9 @@ client.on('interactionCreate', async interaction => {
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error creating static or assigning roles:', error)
|
||||
|
||||
interaction.guild.channels.delete(static_text_channel)
|
||||
interaction.guild.channels.delete(static_voice_channel)
|
||||
interaction.reply({
|
||||
content: 'An error occurred while creating the static. Please try again or contact an admin.',
|
||||
ephemeral: true,
|
||||
@@ -223,20 +226,20 @@ client.on('interactionCreate', async interaction => {
|
||||
}
|
||||
})
|
||||
|
||||
client.on('messageReactionAdd', async (reaction, user) => {
|
||||
/* client.on('messageReactionAdd', async (reaction, user) => {
|
||||
messageReactionAdd(user, reaction)
|
||||
})
|
||||
|
||||
client.on('messageReactionRemove', async (reaction, user) => {
|
||||
messageReactionRemove(user, reaction)
|
||||
})
|
||||
}) */
|
||||
|
||||
client.once('ready', async () => {
|
||||
console.log(`Logged in as ${client.user.tag} `)
|
||||
startBirthdayCheckCron(client)
|
||||
startEventCheckCron(client)
|
||||
updateGlobalMessage(client)
|
||||
initReactionPerRole(client)
|
||||
//initReactionPerRole(client)
|
||||
})
|
||||
|
||||
const connectDiscord = async () => {
|
||||
@@ -280,7 +283,7 @@ const connectDiscord = async () => {
|
||||
.setDescription('The in-game name of the player')
|
||||
.setRequired(true)
|
||||
),
|
||||
new SlashCommandBuilder()
|
||||
/* new SlashCommandBuilder()
|
||||
.setName('static-create')
|
||||
.setDescription('Create a new static with a voice and text channel just for your members.')
|
||||
.addStringOption(option =>
|
||||
@@ -297,7 +300,7 @@ const connectDiscord = async () => {
|
||||
option.setName('members')
|
||||
.setDescription('Optionally assign members here by a comma seperated list (user1,user2,user3...).')
|
||||
.setRequired(false)
|
||||
)
|
||||
) */
|
||||
].map(command => command.toJSON())
|
||||
|
||||
await rest.put(
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
const { CreateStatic, ReadStatic, DeleteStatic } = require('../database/staticdb')
|
||||
|
||||
const handleStaticAdd = async (name, creator, members, size) => {
|
||||
if (!name || !creator || !members || !size) return false
|
||||
const handleStaticAdd = async (name, creator, members, size, role_id, text_channel_id, voice_channel_id) => {
|
||||
if (!name || !creator || !role_id || !text_channel_id || !voice_channel_id) return false
|
||||
|
||||
const result = await CreateStatic(name, creator, members, size)
|
||||
const result = await CreateStatic(
|
||||
name, creator, members, size, role_id, text_channel_id, voice_channel_id
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ const convertToISO = (time, date) => {
|
||||
const convertToUTC = (time) => {
|
||||
const [hours, minutes, seconds] = time.split(':').map(Number)
|
||||
const date = new Date()
|
||||
date.setUTCHours(hours - 2, minutes, seconds)
|
||||
date.setUTCHours(hours - 1, minutes, seconds)
|
||||
return date.toISOString().split('.')[0]
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ const startEventCheckCron = async (client) => {
|
||||
eventCache.forEach(async (event) => {
|
||||
let { schedule_id, event_name, start_time, end_time, day_of_week } = event
|
||||
if (!((!day_of_week || day_of_week === getDayOfWeek()) && isReminderTime(convertToUTC(start_time)))) return
|
||||
|
||||
const rolesEventMap = await GetEventRole()
|
||||
const role = guild.roles.cache.find(r => r.name === rolesEventMap.get(event_name))
|
||||
const roleId = role ? role.id : null
|
||||
@@ -70,6 +69,23 @@ const startEventCheckCron = async (client) => {
|
||||
})
|
||||
}
|
||||
})
|
||||
cron.schedule('0 6 * * *', async () => {
|
||||
for (const [_, oauthGuild] of await client.guilds.fetch()) {
|
||||
const guild = await oauthGuild.fetch()
|
||||
const channel = (await guild.channels.fetch()).find(ch => ch.name === 'reminder')
|
||||
|
||||
if (!channel) continue
|
||||
|
||||
try {
|
||||
const messages = await channel.messages.fetch({ limit: 1000 })
|
||||
messages.forEach(async (message) => {
|
||||
await message.delete().catch(console.error)
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error clearing messages:', error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user