Browse Source

Code formatting cleanup

develop
Drew Short 4 years ago
parent
commit
c28fb72fc3
  1. 20
      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

20
bot/bot.js

@ -67,7 +67,7 @@ class Bot {
let startServerConnection = async () => {
logger.info("Starting Matrix SDK Client");
await this.client.startClient();
}
}
let connectWithPassword = (err, data) => {
if (err === null) {
@ -96,7 +96,7 @@ class Bot {
botClient.loginWithToken(this.config.accessToken, connectWithToken);
}
updateAvatar(avatarFile, overwrite=false) {
updateAvatar(avatarFile, overwrite = false) {
let matrixClient = this.client;
let botConfig = this.config;
let promises = [Promise.resolve(true)];
@ -104,7 +104,7 @@ class Bot {
promises.push(this.client.getProfileInfo(this.config.userId, "avatar_url")
.then((existingAvatarUrl) => {
logger.info("Recieved avatar_url: %o", existingAvatarUrl);
if (typeof existingAvatarUrl !== 'undefined' && typeof existingAvatarUrl == 'object'
if (typeof existingAvatarUrl !== 'undefined' && typeof existingAvatarUrl == 'object'
&& existingAvatarUrl.constructor === Object && Object.keys(existingAvatarUrl).length !== 0
&& !overwrite) {
logger.info("Avatar already set");
@ -117,13 +117,13 @@ class Bot {
type: "image/jpeg",
rawResponse: false
}).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 {

4
bot/config.js

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

4
bot/engine.js

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

2
bot/message.js

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

8
bot/module/giphy.js

@ -36,10 +36,10 @@ class GiphyModule extends AbstractModule {
*/
cmd_search(...args) {
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
*/
let admin = require('./admin');
let giphy = require('./giphy')
let admin = require('./admin');
let giphy = require('./giphy')
function getModules() {
return [

Loading…
Cancel
Save