mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-05 21:17:43 -05:00
Use aliases for !formathelp broadcast cooldown
(This makes it so if someone uses `!om sketch` it will prevent use of `!om sketchmons` for a while.) Suggestion thread: https://www.smogon.com/forums/threads/make-the-broadcast-cooldown-for-commands-apply-to-aliases-of-that-command.3684569/
This commit is contained in:
parent
4a2d386c55
commit
4a716f1456
|
|
@ -1792,40 +1792,43 @@ export const commands: Chat.ChatCommands = {
|
|||
const {totalMatches, sections} = findFormats(targetId, isOMSearch);
|
||||
|
||||
if (!totalMatches) return this.errorReply("No matched formats found.");
|
||||
if (!this.runBroadcast()) return;
|
||||
if (totalMatches === 1) {
|
||||
|
||||
const format = totalMatches === 1 ? Dex.formats.get(Object.values(sections)[0].formats[0]) : null;
|
||||
|
||||
if (!this.runBroadcast(`!formathelp ${format ? format.id : target}`)) return;
|
||||
|
||||
if (format) {
|
||||
const rules: string[] = [];
|
||||
let rulesetHtml = '';
|
||||
const subformat = Dex.formats.get(Object.values(sections)[0].formats[0]);
|
||||
if (['Format', 'Rule', 'ValidatorRule'].includes(subformat.effectType)) {
|
||||
if (subformat.ruleset?.length) {
|
||||
rules.push(`<b>Ruleset</b> - ${Utils.escapeHTML(subformat.ruleset.join(", "))}`);
|
||||
if (['Format', 'Rule', 'ValidatorRule'].includes(format.effectType)) {
|
||||
if (format.ruleset?.length) {
|
||||
rules.push(`<b>Ruleset</b> - ${Utils.escapeHTML(format.ruleset.join(", "))}`);
|
||||
}
|
||||
if (subformat.banlist?.length) {
|
||||
rules.push(`<b>Bans</b> - ${Utils.escapeHTML(subformat.banlist.join(", "))}`);
|
||||
if (format.banlist?.length) {
|
||||
rules.push(`<b>Bans</b> - ${Utils.escapeHTML(format.banlist.join(", "))}`);
|
||||
}
|
||||
if (subformat.unbanlist?.length) {
|
||||
rules.push(`<b>Unbans</b> - ${Utils.escapeHTML(subformat.unbanlist.join(", "))}`);
|
||||
if (format.unbanlist?.length) {
|
||||
rules.push(`<b>Unbans</b> - ${Utils.escapeHTML(format.unbanlist.join(", "))}`);
|
||||
}
|
||||
if (subformat.restricted?.length) {
|
||||
rules.push(`<b>Restricted</b> - ${Utils.escapeHTML(subformat.restricted.join(", "))}`);
|
||||
if (format.restricted?.length) {
|
||||
rules.push(`<b>Restricted</b> - ${Utils.escapeHTML(format.restricted.join(", "))}`);
|
||||
}
|
||||
if (rules.length > 0) {
|
||||
rulesetHtml = `<details><summary>Banlist/Ruleset</summary>${rules.join("<br />")}</details>`;
|
||||
} else {
|
||||
rulesetHtml = `No ruleset found for ${subformat.name}`;
|
||||
rulesetHtml = `No ruleset found for ${format.name}`;
|
||||
}
|
||||
}
|
||||
let formatType: string = (subformat.gameType || "singles");
|
||||
let formatType: string = (format.gameType || "singles");
|
||||
formatType = formatType.charAt(0).toUpperCase() + formatType.slice(1).toLowerCase();
|
||||
if (!subformat.desc && !subformat.threads) {
|
||||
if (subformat.effectType === 'Format') {
|
||||
return this.sendReplyBox(`No description found for this ${formatType} ${subformat.section} format.<br />${rulesetHtml}`);
|
||||
if (!format.desc && !format.threads) {
|
||||
if (format.effectType === 'Format') {
|
||||
return this.sendReplyBox(`No description found for this ${formatType} ${format.section} format.<br />${rulesetHtml}`);
|
||||
} else {
|
||||
return this.sendReplyBox(`No description found for this rule.<br />${rulesetHtml}`);
|
||||
}
|
||||
}
|
||||
const descHtml = [...(subformat.desc ? [subformat.desc] : []), ...(subformat.threads || [])];
|
||||
const descHtml = [...(format.desc ? [format.desc] : []), ...(format.threads || [])];
|
||||
return this.sendReplyBox(`${descHtml.join("<br />")}<br />${rulesetHtml}`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,34 +47,29 @@ function getMegaStone(stone: string, mod = 'gen8'): Item | null {
|
|||
export const commands: Chat.ChatCommands = {
|
||||
om: 'othermetas',
|
||||
othermetas(target, room, user) {
|
||||
this.runBroadcast();
|
||||
target = toID(target);
|
||||
let buffer = ``;
|
||||
const omLink = `- <a href="https://www.smogon.com/forums/forums/531/">Other Metagames Forum</a><br />`;
|
||||
|
||||
if (target === 'all' && this.broadcasting) {
|
||||
throw new Chat.ErrorMessage(`You cannot broadcast information about all Other Metagames at once.`);
|
||||
if (!target) {
|
||||
this.runBroadcast();
|
||||
return this.sendReplyBox(omLink);
|
||||
}
|
||||
|
||||
if (!target || target === 'all') {
|
||||
buffer += `- <a href="https://www.smogon.com/forums/forums/531/">Other Metagames Forum</a><br />`;
|
||||
if (!target) return this.sendReplyBox(buffer);
|
||||
}
|
||||
const showMonthly = (target === 'all' || target === 'omofthemonth' || target === 'month');
|
||||
|
||||
if (target === 'all') {
|
||||
this.runBroadcast();
|
||||
if (this.broadcasting) {
|
||||
throw new Chat.ErrorMessage(`You cannot broadcast information about all Other Metagames at once.`);
|
||||
}
|
||||
// Display OMotM formats, with forum thread links as caption
|
||||
this.parse(`/formathelp omofthemonth`);
|
||||
|
||||
// Display the rest of OM formats, with OM hub/index forum links as caption
|
||||
this.parse(`/formathelp othermetagames`);
|
||||
return this.sendReply(`|raw|<center>${buffer}</center>`);
|
||||
}
|
||||
if (showMonthly) {
|
||||
this.target = 'omofthemonth';
|
||||
this.run('formathelp');
|
||||
} else {
|
||||
this.run('formathelp');
|
||||
return this.sendReply(`|raw|<center>${omLink}</center>`);
|
||||
}
|
||||
|
||||
if (target === 'month') this.target = 'omofthemonth';
|
||||
this.run('formathelp');
|
||||
},
|
||||
othermetashelp: [
|
||||
`/om - Provides links to information on the Other Metagames.`,
|
||||
|
|
|
|||
|
|
@ -956,7 +956,7 @@ export class CommandContext extends MessageContext {
|
|||
shouldBroadcast() {
|
||||
return this.cmdToken === BROADCAST_TOKEN;
|
||||
}
|
||||
checkBroadcast(ignoreCooldown?: boolean, suppressMessage?: string | null) {
|
||||
checkBroadcast(overrideCooldown?: boolean | string, suppressMessage?: string | null) {
|
||||
if (this.broadcasting || !this.shouldBroadcast()) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -973,10 +973,13 @@ export class CommandContext extends MessageContext {
|
|||
|
||||
// broadcast cooldown
|
||||
const broadcastMessage = (suppressMessage || this.message).toLowerCase().replace(/[^a-z0-9\s!,]/g, '');
|
||||
const cooldownMessage = overrideCooldown === true ? null : (overrideCooldown || broadcastMessage);
|
||||
|
||||
if (!ignoreCooldown && this.room && this.room.lastBroadcast === broadcastMessage &&
|
||||
if (
|
||||
cooldownMessage && this.room && this.room.lastBroadcast === cooldownMessage &&
|
||||
this.room.lastBroadcastTime >= Date.now() - BROADCAST_COOLDOWN &&
|
||||
!this.user.can('bypassall')) {
|
||||
!this.user.can('bypassall')
|
||||
) {
|
||||
throw new Chat.ErrorMessage("You can't broadcast this because it was just broadcasted.");
|
||||
}
|
||||
|
||||
|
|
@ -990,7 +993,7 @@ export class CommandContext extends MessageContext {
|
|||
this.broadcastMessage = broadcastMessage;
|
||||
return true;
|
||||
}
|
||||
runBroadcast(ignoreCooldown = false, suppressMessage: string | null = null) {
|
||||
runBroadcast(overrideCooldown?: boolean | string, suppressMessage: string | null = null) {
|
||||
if (this.broadcasting || !this.shouldBroadcast()) {
|
||||
// Already being broadcast, or the user doesn't intend to broadcast.
|
||||
return true;
|
||||
|
|
@ -998,7 +1001,7 @@ export class CommandContext extends MessageContext {
|
|||
|
||||
if (!this.broadcastMessage) {
|
||||
// Permission hasn't been checked yet. Do it now.
|
||||
this.checkBroadcast(ignoreCooldown, suppressMessage);
|
||||
this.checkBroadcast(overrideCooldown, suppressMessage);
|
||||
}
|
||||
|
||||
this.broadcasting = true;
|
||||
|
|
@ -1012,8 +1015,8 @@ export class CommandContext extends MessageContext {
|
|||
// We don't want broadcasted messages in a room to be translated
|
||||
// according to a user's personal language setting.
|
||||
this.language = this.room.settings.language || null;
|
||||
if (!ignoreCooldown) {
|
||||
this.room.lastBroadcast = this.broadcastMessage;
|
||||
if (overrideCooldown !== true) {
|
||||
this.room.lastBroadcast = overrideCooldown || this.broadcastMessage;
|
||||
this.room.lastBroadcastTime = Date.now();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user