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