Skip to content

Commit

Permalink
Add /help perms and /reminderlist.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Apr 21, 2021
1 parent 6d2d2b6 commit 75cd274
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server/bot/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TP \`/request\` - Request a specific feature.
\`/weather\` - It's really cloudy here..
\`/say\` | \`/type\` - Say something, even in another channel.
\`/editLastSay\` - Even if it was another channel.
\`/remindme\` - Reminders.
\`/remindme\` | \`/reminderlist\` - Reminders.
\`/leave\` - Makes you leave the server.
\`/ocr\` - Get text from an image.
\`/avatar\` - Avatar of a user.
Expand Down Expand Up @@ -68,19 +68,32 @@ TP \`/request\` - Request a specific feature.
}

const generateDocs = (command: Command) => {
const permissions = command.requirements.permissions
? `Needs the permissions: ${Object.keys(command.requirements.permissions).map(perm => (
perm.substr(0, 1).toUpperCase() + perm.substr(1)
).replace(/[A-Z]+/g, s => ' ' + s).trim()).join(', ').replace('TTSMessages', 'TTS Messages')} | ` : ''
const roleNames = command.requirements.roleNames
? `Needs the roles: ${command.requirements.roleNames.join(', ')} | ` : ''
const roleIDs = command.requirements.roleIDs ? 'Usable by users with a certain role | ' : ''
const userIDs = command.requirements.userIDs ? 'Usable by certain users | ' : ''
const custom = command.requirements.custom
? '\n**Requirements:** Has some unknown permission checks | ' : ''
const requirements = custom || (permissions || roleIDs || roleNames || userIDs
? `\n**Requirements:** ${custom}${permissions}${roleIDs}${roleNames}${userIDs}` : '')

if (command.aliases && command.aliases.length) {
return `
**Usage:** ${command.usage}
**Aliases:** ${command.aliases.map(i => '/' + i).join(', ')}
**Description:** ${command.fullDescription}
**Example:** ${command.example}
**Example:** ${command.example}${requirements.substr(0, requirements.length - 3)}
Arguments in () are optional :P
`
}
return `
**Usage:** ${command.usage}
**Description:** ${command.fullDescription}
**Example:** ${command.example}
**Example:** ${command.example}${requirements.substr(0, requirements.length - 3)}
Arguments in () are optional :P
`
}
Expand Down
42 changes: 42 additions & 0 deletions server/bot/commands/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,48 @@ export const handleRemindme: Command = {
}
}

export const handleReminderlist: Command = {
name: 'reminderlist',
aliases: ['remindmelist', 'remindlist', 'rmlist', 'rml'],
opts: {
description: 'List the reminders I\'ve set.',
fullDescription: 'List the reminders I\'ve set.',
usage: '/reminderlist',
example: '/reminderlist',
argsRequired: false
},
generator: async (message, args, { db }) => {
// If improper arguments were provided, then we must inform the user.
if (args.length > 0 && message.author.id !== host) return 'Correct usage: /reminderlist'
// Now find the user ID.
let user = args[0] && getUser(message, args[0])
if (!user && args.length) return `Specify a valid member of this guild, ${getInsult()}.`
else if (!user) user = message.author
// Get a list of reminders.
const id = user.id
const reminders = await db.collection('tasks').find({ type: 'reminder', user: id }).toArray()
// If the person has no reminders..
if (reminders.length === 0) return '**No** reminders found.'
// Generate the response.
const format = 'dddd, MMMM Do YYYY, h:mm:ss A' // Date format.
return {
content: `⏰ **Reminders for ${user.username}#${user.discriminator}:**`,
embed: {
color: 0x00AE86,
type: 'rich',
title: 'Reminders',
// This function generates the fields.
fields: reminders.map((reminder, index) => ({
name: `Reminder ${index + 1}`,
value: `**Due time:** ${moment(reminder.time).format(format)}
**Channel:** <#${reminder.target}>
**Message:** ${reminder.message.substring(1, reminder.message.lastIndexOf('\n')).trim()}`
}))
}
}
}
}

export const handleAvatar: Command = {
name: 'avatar',
aliases: ['av'],
Expand Down

0 comments on commit 75cd274

Please sign in to comment.