Skip to content

Commit

Permalink
Merge 65aed92 into 71b2ff9
Browse files Browse the repository at this point in the history
  • Loading branch information
naterchrdsn committed Apr 27, 2018
2 parents 71b2ff9 + 65aed92 commit aca8ec9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"homepage": "https://github.com/FabricLabs/doorman#readme",
"dependencies": {
"@slack/client": "^4.1.0",
"discord.js": "^11.3.2",
"erm": "^0.0.1",
"marked": "^0.3.19",
"matrix-js-sdk": "^0.10.1"
Expand Down
36 changes: 36 additions & 0 deletions services/discord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const util = require('util');
const DiscordJS = require('discord.js');
const Service = require('../lib/service');

function Discord(config) {
this.config = config || {};
this.connection = null;
this.map = {};
}

util.inherits(Discord, Service);

Discord.prototype.connect = function initialize() {
if (this.config.bot_token) {
this.connection = new DiscordJS.Client();
this.connection.login(this.config.bot_token);
this.connection.on('ready', this.ready.bind(this));
this.connection.on('message', this.handler.bind(this));
}
};

Discord.prototype.handler = function route(message) {
this.emit('message', {
actor: message.author.id,
target: message.channel.id,
object: message.content
});
};

Discord.prototype.send = function send(channel, message) {
this.connection.channels.get(channel).send(message);
};

module.exports = Discord;

0 comments on commit aca8ec9

Please sign in to comment.