diff --git a/server/bot/commands/utilities.ts b/server/bot/commands/utilities.ts index 63e9f22..0a7618c 100644 --- a/server/bot/commands/utilities.ts +++ b/server/bot/commands/utilities.ts @@ -138,17 +138,27 @@ export const handleRequest: Command = { name: 'request', aliases: ['req'], opts: { - requirements: { userIDs: [...testPilots, host] }, description: 'Request a specific feature.', - fullDescription: 'Request a feature. Only available to test pilots.', + fullDescription: 'Request a feature. 24 hour cooldown except for test pilots.', usage: '/request ', example: '/request a /userinfo command.' }, - generator: async ({ author, content, channel }, args, { client }) => { - client.createMessage( - (await client.getDMChannel(host)).id, + generator: async ({ author }, args, { client, tempDB }) => { + // Check for cooldown. + if (!testPilots.includes(author.id) && + host !== author.id && tempDB.cooldowns.request.includes(author.id) + ) return 'This command is cooling down right now. Try again later.' + client.createMessage((await client.getDMChannel(host)).id, `${author.username}#${author.discriminator} with ID ${author.id}: ${args.join(' ')}` ) + // Add cooldown. + if (!testPilots.includes(author.id) && host !== author.id) { + tempDB.cooldowns.request.push(author.id) + setTimeout(async () => (tempDB.cooldowns.request.splice( + tempDB.cooldowns.request.findIndex(i => i === author.id), 1 + )), ms('1 day')) + } + // Confirm the request. return `${author.mention}, what a pathetic idea. It has been DMed to the main developer \ and will be read shortly. You may recieve a response soon, and you can keep track here: diff --git a/server/bot/imports/types.ts b/server/bot/imports/types.ts index e1ca6e2..85d6c36 100644 --- a/server/bot/imports/types.ts +++ b/server/bot/imports/types.ts @@ -23,6 +23,7 @@ export type DB = { link: { [index: string]: string }, + cooldowns: { request: string[] }, leave: Array } diff --git a/server/bot/index.ts b/server/bot/index.ts index 01974f6..f4dfecd 100644 --- a/server/bot/index.ts +++ b/server/bot/index.ts @@ -24,11 +24,13 @@ export const guildMemberAdd = (client: Client, db: Db, tempDB: DB) => async ( if (serverSettings.joinAutorole) { // For each role.. serverSettings.joinAutorole.split('|').forEach((role: string) => { - const roleName = role.startsWith('bot-') ? role.substr(4) : role - const roleID = member.guild.roles.find(element => element.name === roleName).id - if (!roleID) return - if (roleName.startsWith('bot-') && member.user.bot) member.addRole(roleID) - else if (!roleName.startsWith('bot-') && !member.user.bot) member.addRole(roleID) + try { + const roleName = role.startsWith('bot-') ? role.substr(4) : role + const roleID = member.guild.roles.find(element => element.name === roleName).id + if (!role) return + if (roleName.startsWith('bot-') && member.user.bot) member.addRole(roleID) + else if (!roleName.startsWith('bot-') && !member.user.bot) member.addRole(roleID) + } catch (e) {} }) } // If join/leave messages is not configured/improperly configured.. @@ -36,12 +38,14 @@ export const guildMemberAdd = (client: Client, db: Db, tempDB: DB) => async ( const { joinMessage, channelName } = serverSettings.joinLeaveMessages if (!channelName || !joinMessage) return // We send a message. - const channelID = guild.channels.find(i => i.name === channelName).id - const toSend = joinMessage - .split('{un}').join(member.user.username) // Replace the username. - .split('{m}').join(member.user.mention) // Replace the mention. - .split('{d}').join(member.user.discriminator) // Replace the discriminator. - try { client.createMessage(channelID, toSend) } catch (e) { } + try { + const channelID = guild.channels.find(i => i.name === channelName).id + const toSend = joinMessage + .split('{un}').join(member.user.username) // Replace the username. + .split('{m}').join(member.user.mention) // Replace the mention. + .split('{d}').join(member.user.discriminator) // Replace the discriminator. + client.createMessage(channelID, toSend) + } catch (e) {} } // When a server loses a member, this function will be called. @@ -55,12 +59,14 @@ export const guildMemberRemove = (client: Client, db: Db) => async ( const { leaveMessage, channelName } = serverSettings.joinLeaveMessages if (!channelName || !leaveMessage) return // We send a message. - const channelID = guild.channels.find(i => i.name === channelName).id - const toSend = leaveMessage - .split('{un}').join(member.user.username) // Replace the username. - .split('{m}').join(member.user.mention) // Replace the mention. - .split('{d}').join(member.user.discriminator) // Replace the discriminator. - try { client.createMessage(channelID, toSend) } catch (e) {} + try { + const channelID = guild.channels.find(i => i.name === channelName).id + const toSend = leaveMessage + .split('{un}').join(member.user.username) // Replace the username. + .split('{m}').join(member.user.mention) // Replace the mention. + .split('{d}').join(member.user.discriminator) // Replace the discriminator. + client.createMessage(channelID, toSend) + } catch (e) {} } // When client recieves a message, it will callback. diff --git a/server/index.ts b/server/index.ts index 55355fd..31a78dc 100644 --- a/server/index.ts +++ b/server/index.ts @@ -93,7 +93,9 @@ client.on('error', (err: string, id: string) => { }) // Create a database to handle certain stuff. -const tempDB: DB = { gunfight: [], say: {}, link: {}, leave: [], mute: {} } +const tempDB: DB = { + gunfight: [], say: {}, link: {}, leave: [], mute: {}, cooldowns: { request: [] } +} /* SERVER CODE STARTS HERE */ // Initialize Next.js app. @@ -116,6 +118,8 @@ app.prepare().then(() => { console.log(`> Ready on http://localhost:${port}`) }) + // On recieving GET on the / endpoint, render /index with Next.js instead of / for SEO. + server.express.get('/', (req, res) => app.render(req, res, '/', req.query)) // On recieving GET on other endpoints, handle with Next.js. server.express.get('*', (req, res) => handle(req, res)) })