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