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. 12
      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();
/* 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);
}
}
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

12
bot/module/admin.js

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

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
*/
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();
Loading…
Cancel
Save