Skip to content

Commit

Permalink
Untested OGP workaround and request now uses 24 hour cooldowns instead.
Browse files Browse the repository at this point in the history
Test pilots and host are exempted from cooldown.
  • Loading branch information
retrixe committed Dec 14, 2018
1 parent 940ecbb commit a20c09a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
20 changes: 15 additions & 5 deletions server/bot/commands/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <suggestion>',
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:
Expand Down
1 change: 1 addition & 0 deletions server/bot/imports/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type DB = {
link: {
[index: string]: string
},
cooldowns: { request: string[] },
leave: Array<string>
}

Expand Down
40 changes: 23 additions & 17 deletions server/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@ 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..
if (!serverSettings.joinLeaveMessages) return
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.
Expand All @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
})
Expand Down

0 comments on commit a20c09a

Please sign in to comment.