-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,4 @@ db.json | |
gh_users.json | ||
filtered_words.json | ||
roles.json | ||
notes.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ContextMenuCommandBuilder } from '@discordjs/builders' | ||
import notes from '../notes.js' | ||
import { ApplicationCommandType } from 'discord-api-types/v9' | ||
|
||
export default { | ||
ephemeral: true, | ||
data: new ContextMenuCommandBuilder() | ||
.setName('Get stored note for user') | ||
.setDefaultPermission(true) | ||
.setType(ApplicationCommandType.User), | ||
permissions: ['moderator', 'helper'], | ||
async execute (interaction) { | ||
const guild = interaction.guild | ||
const member = await guild.members.fetch(interaction.targetId) | ||
if (!member) { | ||
return | ||
} | ||
return interaction.followUp(notes.getNote(member.user)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { SlashCommandBuilder } from '@discordjs/builders' | ||
import notes from '../notes.js' | ||
|
||
export default { | ||
ephemeral: true, | ||
data: new SlashCommandBuilder() | ||
.setName('note') | ||
.setDescription('Manage shared notes for users') | ||
.addSubcommand(sub => sub | ||
.setName('get') | ||
.setDescription('Get the shared note for a user') | ||
.addUserOption(option => option | ||
.setName('user') | ||
.setDescription('The user to get the note for') | ||
.setRequired(true)) | ||
) | ||
.addSubcommand(sub => sub | ||
.setName('set') | ||
.setDescription('Set the shared note for a user') | ||
.addUserOption(option => option | ||
.setName('user') | ||
.setDescription('The user to set the note for') | ||
.setRequired(true)) | ||
.addStringOption(option => option | ||
.setName('value') | ||
.setDescription('New note for the user') | ||
.setRequired(true)) | ||
) | ||
.addSubcommand(sub => sub | ||
.setName('del') | ||
.setDescription('Delete the shared note for a user') | ||
.addUserOption(option => option | ||
.setName('user') | ||
.setDescription('The user to delete the note from') | ||
.setRequired(true)) | ||
), | ||
permissions: ['moderator', 'helper'], | ||
async execute (interaction) { | ||
const user = interaction.options.getUser('user') | ||
|
||
switch (interaction.options.getSubcommand()) { | ||
case 'get': | ||
return interaction.followUp(notes.getNote(user)) | ||
case 'set': { | ||
const value = interaction.options.getString('value') | ||
return interaction.followUp(await notes.setNote(user, value, interaction.guild, interaction.user.tag)) | ||
} | ||
case 'del': | ||
return interaction.followUp(await notes.setNote(user, null, interaction.guild, interaction.user.tag)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { noteDb } from './db.js' | ||
import { buildUserDetail } from './security.js' | ||
import config from './config.js' | ||
|
||
function getNote (user) { | ||
const note = noteDb.get(user.id) | ||
|
||
if (!note) { | ||
return `No stored note for ${buildUserDetail(user)}` | ||
} else { | ||
return `Stored note for ${buildUserDetail(user)}:\n\`${note}\`` | ||
} | ||
} | ||
|
||
async function setNote (user, value, guild, setter) { | ||
const oldNote = noteDb.get(user.id) | ||
if (!oldNote && !value) { | ||
return 'There was no note to remove' | ||
} | ||
noteDb.put(user.id, value) | ||
|
||
let message | ||
|
||
if (!oldNote) { | ||
message = `Set note for ${buildUserDetail(user)} to:\n\`${value}\`` | ||
} else if (!value) { | ||
message = `Deleted note for ${buildUserDetail(user)}:\n\`${oldNote}\`` | ||
} else { | ||
message = `Updated note for ${buildUserDetail(user)}:\nOld: \`${oldNote}\`\nNew: \`${value}\`` | ||
} | ||
|
||
const logs = guild.channels.cache.find(c => c.name === config.channels.moderationLogs) | ||
if (logs) { | ||
await logs.send(`:pencil2: **${setter}** ${message}`) | ||
} | ||
return message | ||
} | ||
|
||
export default { | ||
getNote, | ||
setNote | ||
} |