From 7e03d89decea59273d4e378073807bf775c38f80 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Sun, 29 Dec 2019 15:58:07 -0600 Subject: [PATCH] Improving module support * Added AbstractModule * Added giphy module * Updated Admin module --- bot/engine.js | 5 +++-- bot/module/abstract.js | 24 ++++++++++++++++++++++++ bot/module/admin.js | 20 ++++++++++++-------- bot/module/giphy.js | 17 +++++++++++++++++ bot/module/index.js | 8 ++++++-- 5 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 bot/module/abstract.js create mode 100644 bot/module/giphy.js diff --git a/bot/engine.js b/bot/engine.js index 3627dff..34c848d 100644 --- a/bot/engine.js +++ b/bot/engine.js @@ -13,12 +13,13 @@ class Engine { this.initModules(); /* Bind Message Parsing */ - let handleMessages = function (event, room, toStartOfTimeline) { + let handleMessages = (event, room, toStartOfTimeline) => { if (event.getType() !== "m.room.message") { logger.debug("Recieved message of type: %s", event.getType()); return; // only use messages + } else { + logger.debug("[%s] %s", room.name, event.event.content.body); } - logger.debug("[%s] %s", room.name, event.event.content.body); } this.bot.init(handleMessages); diff --git a/bot/module/abstract.js b/bot/module/abstract.js new file mode 100644 index 0000000..5a1441d --- /dev/null +++ b/bot/module/abstract.js @@ -0,0 +1,24 @@ +/** + * Base module that all modules extend + */ + +let { logger } = require('../logging'); + +class AbstractModule { + name = "AbstractModule" + description = "Base Module That All Other Modules Extend" + command = "abstract_module" + + constructor(name, description, command) { + this.name = name; + this.description = description; + this.command = command; + } + + handleMessage(event, room) { + logger.debug("[%s] [%s] [%s]", this.name, room.name, event.event.content.body); + } + +} + +exports.AbstractModule = AbstractModule \ No newline at end of file diff --git a/bot/module/admin.js b/bot/module/admin.js index 729e000..08dff6b 100644 --- a/bot/module/admin.js +++ b/bot/module/admin.js @@ -2,12 +2,16 @@ * Administration module */ - class AdminModule { - constructor() { - this.name = "Administration" - this.description = "Support administration tasks" - this.command = "admin" - } - } +let { AbstractModule } = require('./abstract'); - exports.module = new AdminModule(); \ No newline at end of file +class AdminModule extends AbstractModule { + constructor() { + super( + "Administration", + "Support administration tasks", + "admin" + ); + } +} + +exports.module = new AdminModule(); \ No newline at end of file diff --git a/bot/module/giphy.js b/bot/module/giphy.js new file mode 100644 index 0000000..ab48fb6 --- /dev/null +++ b/bot/module/giphy.js @@ -0,0 +1,17 @@ +/** + * Giphy module + */ + +let { AbstractModule } = require('./abstract'); + +class GiphyModule extends AbstractModule { + constructor() { + super( + "Giphy", + "Insert Giphy Links/Media", + "giphy" + ); + } +} + +exports.module = new GiphyModule(); \ No newline at end of file diff --git a/bot/module/index.js b/bot/module/index.js index 1c36a30..cd1220f 100644 --- a/bot/module/index.js +++ b/bot/module/index.js @@ -2,10 +2,14 @@ * Manage the registered modules */ - let adminModule = require('./admin'); + let admin = require('./admin'); + let giphy = require('./giphy') function getModules() { - return [adminModule.module]; + return [ + admin.module, + giphy.module + ]; } exports.modules = getModules(); \ No newline at end of file