Skip to content

Commit

Permalink
Fix the build and #22
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy1981 committed Oct 21, 2023
1 parent d35274e commit 8c0668c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"rules": {
"semi": [2, "always"],
"quotes": [2, "single", { "avoidEscape": true }]
"quotes": [2, "single", { "avoidEscape": false }]
}
}
13 changes: 13 additions & 0 deletions __tests__/replacer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ describe('Tests the replacer module', () => {
expect('a'.replace(sut.search, sut.replacement)).toBe('a');
expect(' a'.replace(sut.search, sut.replacement)).toBe('b');
});

it('tests that multiple concurrent replacementsi n asingle string get formatted correctly', () => {
const sut = splitReplaceCommand('!s z/t');
const messages = [{
content: 'nice peppy buzz',
author: 'author'
}];
const expected = 'author nice peppy bu**tt**';
const actual = replaceFirstMessage(messages, sut.search, sut.replacement, channel);

expect(actual).toBe(false);
expect(channel.send).toBeCalledWith(expected);
});

it.each(['', null, undefined, false, 0])('tests the case for no replacement', (emptyIshStringIsh) => {
const regex = new RegExp('hog wild', 'gi');
Expand Down
8 changes: 6 additions & 2 deletions replacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ function replaceFirstMessage(messages, regex, replacement, channel) {

let replacePhrase = '';
if(replacement?.length > 0) {
replacePhrase = cleansedMessageText.replace(regex, '**' + replacement + '**');
replacePhrase = cleansedMessageText
.replace(regex, '\v' + replacement + '\v')
.replace('\v\v', '')
.replace(/\v/g, '**');

}
else {
replacePhrase = msg.content.replace(regex, '');
Expand Down Expand Up @@ -74,7 +78,7 @@ function splitReplaceCommand(replaceCommand) {
return {
search,
replacement: response[1]
}
};
}

module.exports = {
Expand Down

0 comments on commit 8c0668c

Please sign in to comment.