Browse Source

Improving module support

* Added AbstractModule
* Added giphy module
* Updated Admin module
pull/10/head
Drew Short 5 years ago
parent
commit
7e03d89dec
  1. 5
      bot/engine.js
  2. 24
      bot/module/abstract.js
  3. 16
      bot/module/admin.js
  4. 17
      bot/module/giphy.js
  5. 8
      bot/module/index.js

5
bot/engine.js

@ -13,13 +13,14 @@ class Engine {
this.initModules(); this.initModules();
/* Bind Message Parsing */ /* Bind Message Parsing */
let handleMessages = function (event, room, toStartOfTimeline) {
let handleMessages = (event, room, toStartOfTimeline) => {
if (event.getType() !== "m.room.message") { if (event.getType() !== "m.room.message") {
logger.debug("Recieved message of type: %s", event.getType()); logger.debug("Recieved message of type: %s", event.getType());
return; // only use messages 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); this.bot.init(handleMessages);

24
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

16
bot/module/admin.js

@ -2,12 +2,16 @@
* Administration module * Administration module
*/ */
class AdminModule {
let { AbstractModule } = require('./abstract');
class AdminModule extends AbstractModule {
constructor() { constructor() {
this.name = "Administration"
this.description = "Support administration tasks"
this.command = "admin"
}
super(
"Administration",
"Support administration tasks",
"admin"
);
} }
}
exports.module = new AdminModule();
exports.module = new AdminModule();

17
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();

8
bot/module/index.js

@ -2,10 +2,14 @@
* Manage the registered modules * Manage the registered modules
*/ */
let adminModule = require('./admin');
let admin = require('./admin');
let giphy = require('./giphy')
function getModules() { function getModules() {
return [adminModule.module];
return [
admin.module,
giphy.module
];
} }
exports.modules = getModules(); exports.modules = getModules();
Loading…
Cancel
Save