Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Commit

Permalink
Update: experimental fix for splitting messages. Replace he for plug-…
Browse files Browse the repository at this point in the history
…message-split
  • Loading branch information
thedark1337 committed Oct 12, 2017
1 parent 6b44907 commit 54f7077
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
23 changes: 9 additions & 14 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const pRetry = require('p-retry');
const WebSocket = require('ws');
const chalk = require('chalk');
const got = require('got');
const plugMessageSplit = require('plug-message-split');
const tough = require('tough-cookie');
const utils = require('./utils');
const Socket = require('./socket.js');
Expand Down Expand Up @@ -442,9 +443,6 @@ class PlugAPI extends EventEmitter3 {
const obj = store(this)._chatQueue.queue.shift();

if (obj) {

// console.log(`Delay: ${store(this)._floodProtectionDelay} Message: ${JSON.stringify(store(this)._chatQueue.queue)} Queue Length: ${store(this)._chatQueue.queue.length}`);

store(this)._sendEvent(PlugAPI.events.CHAT, obj.msg);
if (!Object.is(obj.timeout, undefined) && isFinite(~~obj.timeout) && ~~obj.timeout > 0) {
const specificChatDeleter = (data) => {
Expand Down Expand Up @@ -1477,7 +1475,7 @@ class PlugAPI extends EventEmitter3 {

/**
* Get a history over chat messages. (Limit 512 messages)
* @returns {Array} Chat history
* @returns {Array<Object>} Chat history
*
* @example
* bot.getChatHistory();
Expand Down Expand Up @@ -1643,14 +1641,11 @@ class PlugAPI extends EventEmitter3 {
if (msg == null) {
return;
}
if (msg.length > 235 && this.multiLine) {
const lines = msg.replace(/.{235}\S*\s+/g, '$&¤').split(/\s+¤/);
const lines = plugMessageSplit.split(msg);

if (lines.length > 1 && this.multiLine) {
for (let i = 0; i < lines.length; i++) {
msg = lines[i];
if (i > 0) {
msg = `(continued) ${msg}`;
}
store(this)._chatQueue.queue.push({
msg,
timeout
Expand Down Expand Up @@ -1716,7 +1711,7 @@ class PlugAPI extends EventEmitter3 {

/**
* Get plug.dj admins currently in the community
* @returns {Array} An array of all admins in the room
* @returns {User[]} An array of all admins in the room
*
* @example
* bot.getAdmins();
Expand Down Expand Up @@ -3304,7 +3299,7 @@ PlugAPI.prototype.moderateLockWaitList = PlugAPI.prototype.moderateLockBooth;
* @prop {String} data.message The chat message.
* @prop {User} data.from The user object of the message sender
* @prop {Object} data.raw The raw data object from plug.dj. Not changed by PlugAPI
* @prop {Array<Object>} data.mentions An array of mentioned users.
* @prop {User[]} data.mentions An array of mentioned users.
* @prop {Boolean} data.muted If the user is muted.
* @prop {String} data.type The message type (mention, emote, messaage)
*
Expand Down Expand Up @@ -3365,10 +3360,10 @@ PlugAPI.prototype.moderateLockWaitList = PlugAPI.prototype.moderateLockBooth;
* @prop {String} data.id The chat id of the message.
* @prop {String} data.command The command message.
* @prop {String} data.message The chat message.
* @prop {Array<Object>|Array<String>} data.args An array of strings / user objects after the command.
* @prop {User[]|Array<String>} data.args An array of strings / user objects after the command.
* @prop {User} data.from The user object of the message sender
* @prop {Object} data.raw The raw data object from plug.dj. Not changed by PlugAPI
* @prop {Array<Object>} data.mentions An array of mentioned users.
* @prop {User[]} data.mentions An array of mentioned users.
* @prop {Boolean} data.muted If the user is muted.
* @prop {String} data.type The message type (mention, emote, messaage)
* @prop {Function} data.isFrom Checks if the message sender is from the inputted array of IDs or ID
Expand Down Expand Up @@ -3590,7 +3585,7 @@ PlugAPI.prototype.moderateLockWaitList = PlugAPI.prototype.moderateLockBooth;
*
* @prop {Object} data.raw The raw object data from plug.dj
* @prop {User} data.moderator The moderator that changed staff roles.
* @prop {Array<User>} data.users an array of users that have had their roles changed. Object is in the format of {role: newRole, user: User Object}
* @prop {User[]} data.users an array of users that have had their roles changed. Object is in the format of {role: newRole, user: User Object}
*
* @example
*
Expand Down
4 changes: 2 additions & 2 deletions lib/eventObjectTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

const he = require('he');
const plugMessageSplit = require('plug-message-split');

module.exports = {

Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = {
raw: data,
id: data.cid,
from: room.getUser(data.uid),
message: he.decode(data.message),
message: plugMessageSplit.unescape(data.message),
mentions: [],
muted: room.isMuted(data.uid),
type: (function() {
Expand Down
4 changes: 2 additions & 2 deletions lib/room.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const he = require('he');
const plugMessageSplit = require('plug-message-split');
const constants = require('./constants.json');

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ class User {
this.slug = data.slug ? data.slug : null;
this.status = data.status != null ? data.status : 1;
this.sub = data.sub ? data.sub : 0;
this.username = he.decode(data.username ? data.username : '');
this.username = plugMessageSplit.unescape(data.username ? data.username : '');
this.vote = instance.votes[data.id] != null ? Object.is(instance.votes[data.id], -1) ? -1 : 1 : 0;
this.xp = data.xp != null ? data.xp : undefined;

Expand Down
16 changes: 11 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"eventemitter3": "^2.0.3",
"got": "^7.0.0",
"handle-errors": "^1.0.0",
"he": "^1.1.1",
"jethro": "^2.7.1",
"p-retry": "^1.0.0",
"plug-message-split": "^1.0.1",
"tough-cookie": "^2.3.2",
"ws": "^3.2.0"
},
Expand Down

0 comments on commit 54f7077

Please sign in to comment.