Skip to content

Commit

Permalink
feat: Added remove command which removes song assigned to a user
Browse files Browse the repository at this point in the history
  • Loading branch information
Donluigimx committed Jun 22, 2021
1 parent 3ed0770 commit bd19eb9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Logger, getUniqueLogger } from './lib/logger';

import AssignCommand from './commands/assign';
import DebugCommand from './commands/debug';
import RemoveCommand from './commands/remove';

import UserConnectedAction from './actions/user-connected';

Expand Down Expand Up @@ -47,6 +48,9 @@ client.on('message', async function(message: Message){
case 'debug':
await DebugCommand(message.author.id, message.guild.id, message.channel);
break;
case 'remove':
await RemoveCommand(message.author.id, message.guild.id, message.channel);
break;
default:
break;
}
Expand Down
36 changes: 36 additions & 0 deletions src/commands/remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Crypto from 'crypto';
import { DMChannel, NewsChannel, TextChannel, MessageEmbed } from 'discord.js';

import Database from '../lib/db';

async function remove(userId: string, serverId: string, textChannel: TextChannel | DMChannel | NewsChannel): Promise<void> {
const hash: string = Crypto.createHash('md5').update(`${userId}${serverId}`).digest('hex');
try {
await new Promise<string>((_, reject) => {
Database.del(hash, (err) => {
if (err) {
reject(err);
}
});
});
} catch (error) {
const embedError: MessageEmbed = new MessageEmbed()
.setColor('#B22222')
.setTitle('Error')
.setDescription('No audio found for user');

await textChannel.send(embedError);

return;
}

const embedResponse: MessageEmbed = new MessageEmbed()
.setColor('#00FFFF')
.setDescription('Song removed');

await textChannel.send(embedResponse);

return;
}

export default remove;

0 comments on commit bd19eb9

Please sign in to comment.