Skip to content

Commit

Permalink
feat(discord): add server started notification (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Jun 12, 2020
1 parent 72415cf commit 765b4df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/discord/services/discord.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ describe('DiscordService', () => {
client.emit('ready');
expect(spy).toHaveBeenCalledWith('FAKE_DISCORD_BOT_TOKEN');
});

it('should send notification', done => {
const spy = jest.spyOn(adminChannel, 'send');
service.onModuleInit();
client.emit('ready');
setTimeout(() => {
expect(spy).toHaveBeenCalled();
done();
}, 0);
});
});

describe('when logged in', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/discord/services/discord.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { Client, Guild, TextChannel, Role } from 'discord.js';
import { Environment } from '@/environment/environment';
import { version } from '../../../package.json';

@Injectable()
export class DiscordService implements OnModuleInit {
Expand All @@ -21,6 +22,7 @@ export class DiscordService implements OnModuleInit {
});

this.client.login(this.environment.discordBotToken)
.then(() => this.getAdminsChannel().send(`Server version ${version} started.`))
.catch(error => this.logger.error(error.toString()));
}
}
Expand Down

0 comments on commit 765b4df

Please sign in to comment.