Browse Source

Code formatting cleanup

develop
Drew Short 5 years ago
parent
commit
c28fb72fc3
  1. 16
      bot/bot.js
  2. 4
      bot/config.js
  3. 4
      bot/engine.js
  4. 2
      bot/message.js
  5. 8
      bot/module/giphy.js
  6. 4
      bot/module/index.js

16
bot/bot.js

@ -96,7 +96,7 @@ class Bot {
botClient.loginWithToken(this.config.accessToken, connectWithToken); botClient.loginWithToken(this.config.accessToken, connectWithToken);
} }
updateAvatar(avatarFile, overwrite=false) {
updateAvatar(avatarFile, overwrite = false) {
let matrixClient = this.client; let matrixClient = this.client;
let botConfig = this.config; let botConfig = this.config;
let promises = [Promise.resolve(true)]; let promises = [Promise.resolve(true)];
@ -117,13 +117,13 @@ class Bot {
type: "image/jpeg", type: "image/jpeg",
rawResponse: false rawResponse: false
}).then((uploadedAvatar) => { }).then((uploadedAvatar) => {
logger.info("Uploaded avatar %o", uploadedAvatar);
matrixClient.setAvatarUrl(uploadedAvatar.content_uri)
.then(() => {
logger.info("Updated %s avatar to %s", botConfig.userId, uploadedAvatar.content_uri);
return true;
});
});
logger.info("Uploaded avatar %o", uploadedAvatar);
matrixClient.setAvatarUrl(uploadedAvatar.content_uri)
.then(() => {
logger.info("Updated %s avatar to %s", botConfig.userId, uploadedAvatar.content_uri);
return true;
});
});
} }
})); }));
} else { } else {

4
bot/config.js

@ -3,7 +3,7 @@ let { logger } = require('./logging');
let loadedConfigs = new Map(); let loadedConfigs = new Map();
function sanitizeConfig(config, fields=[]) {
function sanitizeConfig(config, fields = []) {
let clonedConfig = { ...config }; let clonedConfig = { ...config };
fields.forEach((field) => { fields.forEach((field) => {
clonedConfig[field] = '******' clonedConfig[field] = '******'
@ -11,7 +11,7 @@ function sanitizeConfig(config, fields=[]) {
return clonedConfig; return clonedConfig;
} }
function getConfig(configFile, sanitizedFields=[], reload=false) {
function getConfig(configFile, sanitizedFields = [], reload = false) {
if (loadedConfigs.has(configFile) && !reload) { if (loadedConfigs.has(configFile) && !reload) {
return loadedConfigs.get(configFile); return loadedConfigs.get(configFile);
} else { } else {

4
bot/engine.js

@ -7,7 +7,7 @@ let message = require('./message');
let utility = require('./utility'); let utility = require('./utility');
let { initModule } = require('./module/abstract'); let { initModule } = require('./module/abstract');
let sentinelValue = '!';
let commandPrefix = '!';
class Engine { class Engine {
constructor(config, bot, modules) { constructor(config, bot, modules) {
@ -65,7 +65,7 @@ class Engine {
} else { } else {
let messageBody = event.event.content.body; let messageBody = event.event.content.body;
logger.debug("[%s] %s", room.name, messageBody); logger.debug("[%s] %s", room.name, messageBody);
if (messageBody.indexOf(sentinelValue) === 0) {
if (messageBody.indexOf(commandPrefix) === 0) {
let command = messageBody.split(' ')[0].substring(1); let command = messageBody.split(' ')[0].substring(1);
if (engine.commandMap.has(command)) { if (engine.commandMap.has(command)) {
engine.commandMap.get(command).handleMessage(event, room, sendResponseMessageCallback(engine.bot)); engine.commandMap.get(command).handleMessage(event, room, sendResponseMessageCallback(engine.bot));

2
bot/message.js

@ -3,7 +3,7 @@ let messageTypes = {
NOTICE: 'm.notice' NOTICE: 'm.notice'
} }
function createBasicMessage(body, msgtype=messageTypes.TEXT) {
function createBasicMessage(body, msgtype = messageTypes.TEXT) {
return { return {
"body": body, "body": body,
"msgtype": msgtype "msgtype": msgtype

8
bot/module/giphy.js

@ -36,10 +36,10 @@ class GiphyModule extends AbstractModule {
*/ */
cmd_search(...args) { cmd_search(...args) {
return this.getGiphySearch(args[0]) return this.getGiphySearch(args[0])
.then((response) => {
// logger.debug("Giphy response: %o", response.data.data[0].url);
return response.data.data[0].embed_url;
})
.then((response) => {
// logger.debug("Giphy response: %o", response.data.data[0].url);
return response.data.data[0].embed_url;
})
} }
} }

4
bot/module/index.js

@ -2,8 +2,8 @@
* Manage the registered modules * Manage the registered modules
*/ */
let admin = require('./admin');
let giphy = require('./giphy')
let admin = require('./admin');
let giphy = require('./giphy')
function getModules() { function getModules() {
return [ return [

Loading…
Cancel
Save