Skip to content

Commit

Permalink
Update client-chat.js
Browse files Browse the repository at this point in the history
added alias for /highlight delete and /highlight roomdelete:
/highlight remove and /highlight roomremove
  • Loading branch information
PacificMarill authored Nov 3, 2024
1 parent 1221756 commit 56bd3ad
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions play.pokemonshowdown.com/js/client-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,49 +865,50 @@
targets[i] = targets[i].replace(/\n/g, '').trim();
}
switch (subCmd) {
case 'add': case 'roomadd':
var key = subCmd === 'roomadd' ? (Config.server.id + '#' + this.id) : 'global';
var highlightList = highlights[key] || [];
for (var i = 0, len = targets.length; i < len; i++) {
if (!targets[i]) continue;
if (/[\\^$*+?()|{}[\]]/.test(targets[i])) {
// Catch any errors thrown by newly added regular expressions so they don't break the entire highlight list
try {
new RegExp(targets[i]);
} catch (e) {
return this.add('|error|' + (e.message.substr(0, 28) === 'Invalid regular expression: ' ? e.message : 'Invalid regular expression: /' + targets[i] + '/: ' + e.message));
case 'add': case 'roomadd':

Check failure on line 868 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 5 tabs but found 6
var key = subCmd === 'roomadd' ? (Config.server.id + '#' + this.id) : 'global';

Check failure on line 869 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 6 tabs but found 7
var highlightList = highlights[key] || [];

Check failure on line 870 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 6 tabs but found 7
for (var i = 0, len = targets.length; i < len; i++) {

Check failure on line 871 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 6 tabs but found 7
if (!targets[i]) continue;

Check failure on line 872 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 7 tabs but found 8
if (/[\\^$*+?()|{}[\]]/.test(targets[i])) {

Check failure on line 873 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 7 tabs but found 8
// Catch any errors thrown by newly added regular expressions so they don't break the entire highlight list

Check failure on line 874 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 8 tabs but found 9
try {

Check failure on line 875 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 8 tabs but found 9
new RegExp(targets[i]);

Check failure on line 876 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 9 tabs but found 10
} catch (e) {

Check failure on line 877 in play.pokemonshowdown.com/js/client-chat.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected indentation of 8 tabs but found 9
return this.add('|error|' + (e.message.substr(0, 28) === 'Invalid regular expression: ' ? e.message : 'Invalid regular expression: /' + targets[i] + '/: ' + e.message));
}
}
if (highlightList.includes(targets[i])) {
return this.add('|error|' + targets[i] + ' is already on your highlights list.');
}
}
if (highlightList.includes(targets[i])) {
return this.add('|error|' + targets[i] + ' is already on your highlights list.');
}
}
highlights[key] = highlightList.concat(targets);
this.add("Now highlighting on " + (key === 'global' ? "(everywhere): " : "(in " + key + "): ") + highlights[key].join(', '));
// We update the regex
this.updateHighlightRegExp(highlights);
break;
case 'delete': case 'roomdelete':
var key = subCmd === 'roomdelete' ? (Config.server.id + '#' + this.id) : 'global';
var highlightList = highlights[key] || [];
var newHls = [];
for (var i = 0, len = highlightList.length; i < len; i++) {
if (targets.indexOf(highlightList[i]) === -1) {
newHls.push(highlightList[i]);
highlights[key] = highlightList.concat(targets);
this.add("Now highlighting on " + (key === 'global' ? "(everywhere): " : "(in " + key + "): ") + highlights[key].join(', '));
// We update the regex
this.updateHighlightRegExp(highlights);
break;
case 'delete': case 'roomdelete':
case 'remove': case 'roomremove': // New aliases
var key = subCmd === 'roomdelete' || subCmd === 'roomremove' ? (Config.server.id + '#' + this.id) : 'global';
var highlightList = highlights[key] || [];
var newHls = [];
for (var i = 0, len = highlightList.length; i < len; i++) {
if (targets.indexOf(highlightList[i]) === -1) {
newHls.push(highlightList[i]);
}
}
}
highlights[key] = newHls;
this.add("Now highlighting on " + (key === 'global' ? "(everywhere): " : "(in " + key + "): ") + highlights[key].join(', '));
// We update the regex
this.updateHighlightRegExp(highlights);
break;
default:
if (this.checkBroadcast(cmd, text)) return false;
// Wrong command
this.add('|error|Invalid /highlight command.');
this.parseCommand('/help highlight'); // show help
return false;
}
highlights[key] = newHls;
this.add("Now highlighting on " + (key === 'global' ? "(everywhere): " : "(in " + key + "): ") + highlights[key].join(', '));
// We update the regex
this.updateHighlightRegExp(highlights);
break;
default:
if (this.checkBroadcast(cmd, text)) return false;
// Wrong command
this.add('|error|Invalid /highlight command.');
this.parseCommand('/help highlight'); // show help
return false;
}
Storage.prefs('highlights', highlights);
} else {
if (this.checkBroadcast(cmd, text)) return false;
Expand Down

0 comments on commit 56bd3ad

Please sign in to comment.