Skip to content

Commit

Permalink
fix(message): remove $sender replace in (!#) and (!!#) (#3640)
Browse files Browse the repository at this point in the history
* fix(message): remove $sender replace in (!#) and (!!#)

Fixes https://discordapp.com/channels/317348946144002050/619437014001123338/706782624416399422

* add missing time import
  • Loading branch information
sogehige committed May 4, 2020
1 parent 5ac531f commit 2db055a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/bot/message.ts
Expand Up @@ -390,7 +390,6 @@ class Message {
const cmd = filter
.replace('!', '') // replace first !
.replace(/\(|\)/g, '')
.replace(/\$sender/g, (tmi.showWithAt ? '@' : '') + attr.sender.username)
.replace(/\$param/g, attr.param);
const parse = new Parser({ sender: attr.sender, message: cmd, skip: true, quiet: true });
const responses = await parse.process();
Expand All @@ -404,7 +403,6 @@ class Message {
'(!#)': async function (filter) {
const cmd = filter
.replace(/\(|\)/g, '')
.replace(/\$sender/g, (tmi.showWithAt ? '@' : '') + attr.sender.username)
.replace(/\$param/g, attr.param);
const parse = new Parser({ sender: attr.sender, message: cmd, skip: true, quiet: false });
const responses = await parse.process();
Expand Down
6 changes: 5 additions & 1 deletion test/tests/commons/#3620_announce_is_not_parsing_filters.js
Expand Up @@ -2,6 +2,7 @@ require('../../general.js');

const db = require('../../general.js').db;
const message = require('../../general.js').message;
const time = require('../../general.js').time;

const api = (require('../../../dest/api')).default;
const alias = (require('../../../dest/systems/alias')).default;
Expand Down Expand Up @@ -35,7 +36,10 @@ describe('Commons - #3620 - announce is not parsing message filters', () => {
isEnabled: true,
timer,
});
api.isStreamOnline = true;
for (let i = 0; i < 2; i++) {
api.isStreamOnline = true;
await time.waitMs(1000);
}
});

it('Timer should trigger announce() with proper response with filters', async () => {
Expand Down
@@ -0,0 +1,48 @@
require('../../general.js');

const db = require('../../general.js').db;
const message = require('../../general.js').message;
const time = require('../../general.js').time;

const api = (require('../../../dest/api')).default;
const alias = (require('../../../dest/systems/alias')).default;
const customcommands = (require('../../../dest/systems/customcommands')).default;

const { getRepository } = require('typeorm');
const { Timer, TimerResponse } = require('../../../dest/database/entity/timer');

const { linesParsed } = require('../../../dest/helpers/parser');

// users
const owner = { username: 'soge__' };

describe('Message - https://discordapp.com/channels/317348946144002050/619437014001123338/706782624416399422 - sender object should be owner on timers with (!#)', () => {
before(async () => {
await db.cleanup();
await message.prepare();
await alias.add({ sender: owner, parameters: '-a !testAlias -c !me' });
await customcommands.add({ sender: owner, parameters: '-c !testCmd -r Lorem Ipsum' });
const timer = await getRepository(Timer).save({
name: 'test',
triggerEveryMessage: 0,
triggerEverySecond: 1,
isEnabled: true,
triggeredAtTimestamp: Date.now(),
triggeredAtMessage: linesParsed,
});
await getRepository(TimerResponse).save({
response: '(!top time)',
timestamp: Date.now(),
isEnabled: true,
timer,
});
for (let i = 0; i < 2; i++) {
api.isStreamOnline = true;
await time.waitMs(1000);
}
});

it('!top time should be properly triggered', async () => {
await message.isSentRaw('Top 10 (watch time): no data available', 'bot', 20000);
});
});

0 comments on commit 2db055a

Please sign in to comment.