Preact: Add support for /warn (#2478)

This commit is contained in:
Aurastic 2025-07-23 06:43:18 +05:30 committed by GitHub
parent cd82eaae61
commit 2b82244cbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 110 additions and 1 deletions

View File

@ -117,6 +117,16 @@ export class ChatRoom extends PSRoom {
if (`${args[2]} `.startsWith('/challenge ')) {
this.updateChallenge(args[1], args[2].slice(11));
return;
} else if (args[2].startsWith('/warn ')) {
const reason = args[2].replace('/warn ', '');
PS.join(`rules-warn` as RoomID, {
args: {
type: 'warn',
message: reason?.trim() || undefined,
},
parentElem: null,
});
return;
}
// falls through
case 'c:':

View File

@ -1813,6 +1813,104 @@ class BattleTimerPanel extends PSRoomPanel {
}
}
class RulesPanel extends PSRoomPanel<PopupRoom> {
static readonly id = 'rules';
static readonly routes = ['rules-*'];
static readonly location = 'modal-popup';
static readonly noURL = true;
static readonly Model = PopupRoom;
declare state: { canClose?: boolean | null, timeLeft?: number | null, timerRef?: any };
override componentDidMount() {
super.componentDidMount();
const args = this.props.room.args;
const isWarn = args?.type === 'warn';
if (isWarn && args) {
const timerRef = setInterval(() => {
const timeLeft = this.state.timeLeft || 5;
const canClose = timeLeft === 1;
this.setState({ canClose, timeLeft: timeLeft - 1 });
if (canClose) {
clearInterval(this.state.timerRef);
this.setState({ timerRef: null });
}
}, 1000);
if (!this.state.timerRef) this.setState({ timerRef });
}
}
override render() {
const room = this.props.room;
const type = room.args?.type;
const isWarn = type === 'warn';
const message = room.args?.message as string || '';
return <PSPanelWrapper room={room} width={room.args?.width as number || 780}>
<div class="pad">
{
isWarn &&
<p><strong style="color:red">{(BattleLog.escapeHTML(message) || 'You have been warned for breaking the rules.')}
</strong></p>
}
<h2>Pok&eacute;mon Showdown Rules</h2>
<p><b>1.</b> Be nice to people. Respect people. Don't be rude or mean to people.</p>
<p><b>2.</b> {' '}
Follow US laws (PS is based in the US). No porn (minors use PS), don't distribute pirated material, {' '}
and don't slander others.</p>
<p><b>3.</b> {' '}
&nbsp;No sex. Don't discuss anything sexually explicit, not even in private messages, {' '}
not even if you're both adults.</p>
<p><b>4.</b> {' '}
&nbsp;No cheating. Don't exploit bugs to gain an unfair advantage. {' '}
Don't game the system (by intentionally losing against yourself or a friend in a ladder match, by timerstalling, etc). {' '}
Don't impersonate staff if you're not.</p>
<p><b>5.</b> {' '}
Moderators have discretion to punish any behaviour they deem inappropriate, whether or not it's on this list. {' '}
If you disagree with a moderator ruling, appeal to an administrator (a user with ~ next to their name) or {' '}
<a href="https://pokemonshowdown.com/appeal">Discipline Appeals</a>.</p>
<p>(Note: The First Amendment does not apply to PS, since PS is not a government organization.)</p>
<p><b>Chat</b></p>
<p><b>1.</b> {' '}
Do not spam, flame, or troll. This includes advertising, raiding, {' '}
asking questions with one-word answers in the lobby, {' '}
and flooding the chat such as by copy/pasting logs in the lobby.</p>
<p><b>2.</b> {' '}
Don't call unnecessary attention to yourself. Don't be obnoxious. ALL CAPS and <i>formatting</i> {' '}
are acceptable to emphasize things, but should be used sparingly, not all the time.</p>
<p><b>3.</b> {' '}
No minimodding: don't mod if it's not your job. Don't tell people they'll be muted, {' '}
don't ask for people to be muted, {' '}
and don't talk about whether or not people should be muted ('inb4 mute\, etc). {' '}
This applies to bans and other punishments, too.</p>
<p><b>4.</b> {' '}
We reserve the right to tell you to stop discussing moderator decisions if you become unreasonable or belligerent</p>
<p><b>5.</b> English only, unless specified otherwise.</p>
<p>(Note: You can opt out of chat rules in private chat rooms and battle rooms, {' '}
but only if all ROs or players agree to it.)</p>
{
!isWarn && <>
<p><b>Usernames</b></p>
<p>Your username can be chosen and changed at any time. Keep in mind:</p>
<p><b>1.</b> Usernames may not impersonate a recognized user (a user with %, @, #, or ~ next to their name) {' '}
or a famous person/organization that uses PS or is associated with Pokémon.</p>
<p><b>2.</b> Usernames may not be derogatory or insulting in nature, to an individual or group {' '}
(insulting yourself is okay as long as it's not too serious).</p>
<p><b>3.</b> Usernames may not directly reference sexual activity, or be excessively disgusting.</p>
<p>This policy is less restrictive than that of many places, so you might see some "borderline" nicknames {' '}
that might not be accepted elsewhere. You might consider it unfair that they are allowed to keep their {' '}
nickname. The fact remains that their nickname follows the above rules, and {' '}
if you were asked to choose a new name, yours does not.</p>
</>
}
<p class="buttonbar"><button
name="close"
data-cmd="/close" class="button autofocus"
disabled={!this.state.canClose}
> Close {this.state.timerRef && <>({this.state.timeLeft} sec)</>}</button></p>
</div>
</PSPanelWrapper>;
}
}
PS.addRoomType(
UserPanel,
UserOptionsPanel,
@ -1831,5 +1929,6 @@ PS.addRoomType(
PopupPanel,
RoomTabListPanel,
BattleOptionsPanel,
BattleTimerPanel
BattleTimerPanel,
RulesPanel
);