mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
Fix misc bugs discovered by LGTM
This commit is contained in:
parent
cd4c996257
commit
769ee0aa86
|
|
@ -777,9 +777,7 @@ const commands = {
|
|||
let roomid = target.trim();
|
||||
if (!roomid) {
|
||||
// allow deleting personal rooms without typing out the room name
|
||||
if (room.isPersonal && cmd === "deletegroupchat") {
|
||||
roomid = room.id;
|
||||
} else {
|
||||
if (!room.isPersonal || cmd !== "deletegroupchat") {
|
||||
return this.parse(`/help deleteroom`);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1063,7 +1061,7 @@ const commands = {
|
|||
}
|
||||
if (!this.can('declare')) return false;
|
||||
if (target.length > 80) return this.errorReply(`Error: Room description is too long (must be at most 80 characters).`);
|
||||
let normalizedTarget = ' ' + target.toLowerCase().replace('[^a-zA-Z0-9]+', ' ').trim() + ' ';
|
||||
let normalizedTarget = ' ' + target.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim() + ' ';
|
||||
|
||||
if (normalizedTarget.includes(' welcome ')) {
|
||||
return this.errorReply(`Error: Room description must not contain the word "welcome".`);
|
||||
|
|
@ -1263,6 +1261,7 @@ const commands = {
|
|||
}
|
||||
if (!target) return this.parse('/help roomowner');
|
||||
target = this.splitTarget(target, true);
|
||||
if (target) return this.errorReply(`This command does not support specifying a reason.`);
|
||||
let targetUser = this.targetUser;
|
||||
let name = this.targetUsername;
|
||||
let userid = toId(name);
|
||||
|
|
@ -1737,6 +1736,7 @@ const commands = {
|
|||
unmute: function (target, room, user) {
|
||||
if (!target) return this.parse('/help unmute');
|
||||
target = this.splitTarget(target);
|
||||
if (target) return this.errorReply(`This command does not support specifying a reason.`);
|
||||
if (!this.canTalk()) return;
|
||||
if (!this.can('mute', null, room)) return false;
|
||||
|
||||
|
|
@ -2224,6 +2224,7 @@ const commands = {
|
|||
if (!this.can('promote')) return;
|
||||
|
||||
target = this.splitTarget(target, true);
|
||||
if (target) return this.errorReply(`This command does not support specifying a reason.`);
|
||||
let targetUser = this.targetUser;
|
||||
let userid = toId(this.targetUsername);
|
||||
let name = targetUser ? targetUser.name : this.targetUsername;
|
||||
|
|
@ -3290,7 +3291,7 @@ const commands = {
|
|||
// errors can occur while rebasing or popping the stash; make sure to recover
|
||||
try {
|
||||
this.sendReply(`Rebasing...`);
|
||||
[code, stdout, stderr] = await exec(`git rebase FETCH_HEAD`);
|
||||
[code] = await exec(`git rebase FETCH_HEAD`);
|
||||
if (code) {
|
||||
// conflict while rebasing
|
||||
await exec(`git rebase --abort`);
|
||||
|
|
@ -3299,7 +3300,7 @@ const commands = {
|
|||
|
||||
if (stashedChanges) {
|
||||
this.sendReply(`Restoring saved changes...`);
|
||||
[code, stdout, stderr] = await exec(`git stash pop`);
|
||||
[code] = await exec(`git stash pop`);
|
||||
if (code) {
|
||||
// conflict while popping stash
|
||||
await exec(`git reset HEAD .`);
|
||||
|
|
@ -3802,12 +3803,8 @@ const commands = {
|
|||
let targetUser = Users.getExact(target);
|
||||
if (!targetUser) return this.errorReply(`User '${target}' not found.`);
|
||||
|
||||
target = targetUser ? targetUser.userid : '';
|
||||
|
||||
if (target) {
|
||||
room.battle.win(targetUser);
|
||||
this.modlog('FORCEWIN', target);
|
||||
}
|
||||
room.battle.win(targetUser);
|
||||
this.modlog('FORCEWIN', targetUser.userid);
|
||||
},
|
||||
forcewinhelp: [
|
||||
`/forcetie - Forces the current match to end in a tie. Requires: & ~`,
|
||||
|
|
@ -3901,6 +3898,7 @@ const commands = {
|
|||
'!accept': true,
|
||||
accept: function (target, room, user, connection) {
|
||||
target = this.splitTarget(target);
|
||||
if (target) return this.popupReply(`This command does not support specifying multiple users`);
|
||||
const targetUser = this.targetUser || this.pmTarget;
|
||||
if (!targetUser) return this.popupReply(`User "${this.targetUsername}" not found.`);
|
||||
Ladders.acceptChallenge(connection, targetUser);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class TextFormatter {
|
|||
|
||||
// filter links first
|
||||
str = str.replace(linkRegex, uri => {
|
||||
let fulluri = uri;
|
||||
let fulluri;
|
||||
if (/^[a-z0-9.]+@/ig.test(uri)) {
|
||||
fulluri = 'mailto:' + uri;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -412,7 +412,6 @@ const commands = {
|
|||
let pokemon = Dex.getTemplate(p);
|
||||
if (pokemon.num === targetNum) {
|
||||
target = pokemon.species;
|
||||
targetId = pokemon.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1536,7 +1535,7 @@ const commands = {
|
|||
break;
|
||||
}
|
||||
|
||||
if (!totalMatches) return this.errorReply("No " + (target ? "matched " : "") + "formats found.");
|
||||
if (!totalMatches) return this.errorReply("No matched formats found.");
|
||||
if (totalMatches === 1) {
|
||||
let rules = [];
|
||||
let rulesetHtml = '';
|
||||
|
|
|
|||
|
|
@ -214,9 +214,9 @@ class Battle extends Dex.ModdedDex {
|
|||
let result = this.runEvent('SetWeather', source, source, status);
|
||||
if (!result) {
|
||||
if (result === false) {
|
||||
if (source && sourceEffect && sourceEffect.weather) {
|
||||
if (sourceEffect && sourceEffect.weather) {
|
||||
this.add('-fail', source, sourceEffect, '[from]: ' + this.weather);
|
||||
} else if (source && sourceEffect && sourceEffect.effectType === 'Ability') {
|
||||
} else if (sourceEffect && sourceEffect.effectType === 'Ability') {
|
||||
this.add('-ability', source, sourceEffect, '[from] ' + this.weather, '[fail]');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
sim/dex.js
12
sim/dex.js
|
|
@ -1041,21 +1041,20 @@ class ModdedDex {
|
|||
return false;
|
||||
}
|
||||
|
||||
/** @type {DataType[]} */
|
||||
searchIn = searchIn || ['Pokedex', 'Movedex', 'Abilities', 'Items', 'Natures'];
|
||||
|
||||
let searchFunctions = {Pokedex: 'getTemplate', Movedex: 'getMove', Abilities: 'getAbility', Items: 'getItem', Natures: 'getNature'};
|
||||
let searchTypes = {Pokedex: 'pokemon', Movedex: 'move', Abilities: 'ability', Items: 'item', Natures: 'nature'};
|
||||
/** @type {AnyObject[] | false} */
|
||||
let searchResults = [];
|
||||
for (const result of searchIn) {
|
||||
for (const table of searchIn) {
|
||||
/** @type {AnyObject} */
|
||||
// @ts-ignore
|
||||
let res = this[searchFunctions[result]](target);
|
||||
let res = this[searchFunctions[table]](target);
|
||||
if (res.exists && res.gen <= this.gen) {
|
||||
searchResults.push({
|
||||
isInexact: isInexact,
|
||||
searchType: searchTypes[result],
|
||||
searchType: searchTypes[table],
|
||||
name: res.species ? res.species : res.name,
|
||||
});
|
||||
}
|
||||
|
|
@ -1077,8 +1076,9 @@ class ModdedDex {
|
|||
maxLd = 2;
|
||||
}
|
||||
searchResults = false;
|
||||
for (let i = 0; i <= searchIn.length; i++) {
|
||||
let searchObj = this.data[searchIn[i] || 'Aliases'];
|
||||
for (const table of [...searchIn, 'Aliases']) {
|
||||
// @ts-ignore
|
||||
let searchObj = this.data[table];
|
||||
if (!searchObj) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user