We were previously using `type Foo = import('bar').Foo` which works
actually equally well, because sucrase didn't support `import type`,
but now it does!
NOTE: This is changes the semantics of `hidenext`/`ionext` from
applying to the next created *battle* to applying to the next
created *search*/*challenge*.
I couldn't completely remove the global room in one commit, but this
solves basically every problem with it by making it no longer a `Room`.
In particular, this means:
- It's no longer of type `Room`
- It's no longer in the `Rooms.rooms` table
- Its class name is now `GlobalRoomState` rather than `GlobalRoom`
- It no longer tracks its own user list (online user count is now
provided by `Users.onlineCount`)
- It's no longer a socket channel (there's new syntax for "send this
message to every user")
This implements two big changes:
- All settings shared between `room.chatRoomData` and `room` have been
merged into `room.settings` (so, for instance, `room.slowchat` is now
only `room.settings.slowchat`).
This makes it so we never have to worry about them getting "out of
sync".
- Checking to see if a room is persistent is now `if (room.persist)`
instead of `if (room.chatRoomData)`
- `Rooms.global.writeChatRoomData()` is now rarely called directly;
there's a new `room.saveSettings()` which will handle it for you.
- All properties of `room.settings` are now optional (except
`title`).
- There's a new file `user-groups.ts` which handles authority.
- `room.auth` and `Users.globalAuth` are now
`Auth extends Map<ID, GroupSymbol>` objects.
- `room.auth` is now always defined, removing the need for
`room.auth?.[userid]` workarounds.
- A lot of code relating to usergroups and permission checks have
been refactored.
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
This is mostly just a follow up to #6342.
`prefer-optional-chaining` was turned on and fixed in every location it
complained in. The transformed function [0] looks expensive from a
glance but from skimming through the replaced sites it doesn't appear
to be ran in any important place, so it should be OK.
The linter improvements are:
- Increase linter performance
- Make `full-lint` and `lint` write to different caches so we
avoid overwriting their caches since they're different configs
- Change husky's hook to `npm run lint` so as to write to the
same cache
- Remove `@typescript-eslint/eslint-plugin-tslint` which is
essentially a wrapper to TSLint because the rules aren't worth
running another linter
- Convert `.eslintrc.json` and `.eslintrc-syntax.json` to two spaces
rather than four tabs to respect PS' `.editorconfig`
- Rename `fulllint` to `full-lint` to ease spelling it
[0] - https://pastie.io/mmtxpf.js (prettified)
The most recent change to this file prevents "/tour autodq off" from working and sends a "That isn't a valid timeout value." error to the client. This is because it checks for a condition where timeout is greater than 1 hour, but when turning autodq off, the timeout variable is set to Infinity. This proposed change adds a check in the condition for if the timeout value is Infinity and does not send the error if that is the case (but if timeout is a numeric value greater than 1 hour, it still will fail).
By adding a `getGame` function of type:
```
// null is returned if the gameids don't match
// or the game doesn't exist
getGame<T extends RoomGame>(constructor: new (...args: any[]) => T) => T | null
```
(Credits @urkerab and @whalemer for the function signature.)
It allows refactoring previous code of:
```
if (room.game && room.game.gameid !== 'hangman') return;
const game = room.game as Hangman;
```
to:
```
const game = room.getGame(Hangman);
if (!game) return;
```
This has a couple of advantages:
- TypeScript will throw an error if the if condition is not present.
- In the new code, the template must extends `RoomGame` and be assignable to the same ID, so it's 100% typesafe
This commit adds a `challengeType` property to `RoomBattle` of
type `rated | unrated | challenge | tour`.
Previously, there was no way to programatically differ an unrated
battle from a challenge, which is useful in places like filters.
This commit changes the TypeScript global variable of `Config` from
`AnyObject` to `Config & AnyObject`.
It still falls back to `AnyObject` (hence the 'Take steps') because of
the main-specific `Config` properties that are used without being in the
`Config` object itself.
These can be added by someone with access to the PS main server.
Regardlesss, this is an improvement as IntelliSense can display and
autocomplete the known properies.
In addition, the TypeScript compiler will now report bugs
concerning the types of the properties, which I have fixed in this
commit.
* Modnote Tours Format and Player Count Start
* Fix Trailing Whitespace on line 610
* String Interpolation Injects Integers Too
No need for a method to change the Integer's type to String
* Add a Private Modaction
* Simplify modnote to just player count
* Update server/tournaments/index.ts
Co-Authored-By: Guangcong Luo <guangcongluo@gmail.com>
* Change CommandContext Element to output
Co-Authored-By: Guangcong Luo <guangcongluo@gmail.com>
* Shorten Modlog Entry
- The big change here is that player.userid can now be empty. You can
now fit state into RoomGamePlayer subclasses even when there are no
users associated with them.
- `game.players` has been introduced as the new canonical list of
players, including userless players. The old `game.players` has been
renamed `game.playerTable`, for clarity.
- `game.addPlayer` now returns the added player
All existing RoomGames have been updated for the new API, and
RoomBattle is now officially a RoomGame subclass.
Tournaments was also massively refactored to be properly updated for
the old API, since that never happened, and should now be a lot more
readable.
It turns out the line `let Punishments = module.exports;` makes it into
`any`, and disables nearly all typechecking of anything to do with
`Punishments`. This refactor fixes that, and also fixes a bunch of flaws
newly caught by TypeScript.
I tried my best not to make any changes to actual functionality. These
changes should be effectively purely code cleanup.
Also move mods/ to data/mods/
This makes PS more monorepo-like. The intent is to further separate
the sim and the server code, but without fully committing to splitting
the repository itself.
We now support `./pokemon-showdown start` in addition to
`./pokemon-showdown`. I'm not clear which I want to be the default
yet.