I wrote a `forceWrap` method to support break-word wrapping in table
cells for scavengers, but apparently code blocks need it too, so I'm
moving it to Utils.
Fixes#7854
It seems every other week TypeScript does an update that affects
whether or not this line needs a cast.
This should probably have been refactored to `typeof` ages ago, because
that one way more reliably doesn't need a cast.
When settings.blockInvites is false or undefined, we should allow room invites to be sent.
However, this code denies it because it thinks that the user sending the message is not of the rank "undefined" (or "false"), which isn't a real rank.
- Default precision is now 3.
(Instead of "3 months 25 days 17 hours 46 minutes 40 seconds", it'll
say "3 months 25 days 17 hours". You can still set the precision to
`Infinity` if you actually prefer that.)
- Now displays "forever" for Infinity or overflow durations
- No longer skips blank precision levels
(Shows "3 hours 0 minutes 10 seconds" instead of
"3 hours 10 seconds")
* Lint arrow-body-style
* Lint prefer-object-spread
Object spread is faster _and_ more readable.
This also fixes a few unnecessary object clones.
* Enable no-parameter-properties
This isn't currently used, but this makes clear that it shouldn't be.
* Refactor more Promises to async/await
* Remove unnecessary code from getDataMoveHTML etc
* Lint prefer-string-starts-ends-with
* Stop using no-undef
According to the typescript-eslint FAQ, this is redundant with
TypeScript, and they're not wrong. This will save us from needing to
specify globals in two different places which will be nice.
This provides a new way to persist chat plugin data across hotpatches:
`Chat.oldPlugins`.
In a plugin, you can now do:
```
export const cache = Chat.oldPlugins.pluginname?.cache || {};
```
to create a cache that will persist across hotpatches.
We're skipping two major typescript-eslint versions, so there are a
bunch of changes here, including:
- it's catching a lot of things it didn't catch in the past, for
reasons unclear to me
- no-unused-vars has to be explicitly disabled in global-types now
- a lot of `ts-ignore`s were never necessary and have been fixed
- Crashlogger can now handle being thrown things that aren't errors.
This has never been a problem in the past, but to satisfy TypeScript
we might as well not die in a fire on the off chance someone tries to
`throw null` or something.
This doesn't really have any nice-to-have automatic restoration
features but it should be all the important parts.
`user.group` no longer exists, and has been replaced with
`user.tempGroup`, which now applies both to temporary promotions of
unregistered users, as well as temporary hidden ranks of auth.
Changes this makes:
a) Lets people use `/pm` or `/w` instead of `/msg` in buttons.
b) Permits the author of the HTML to direct messages towards themselves via buttons (useful for when Bots creates subroomgroupchats and become *, or if they suddenly want hugs from random people).
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
Co-authored-by: Mia <49593536+mia-pi-git@users.noreply.github.com>
Private commands can now use `this.privatelyCan` instead of `this.can`
to automatically display "command not found" in the command
(and in Help) for permission failure. They can also use
`this.commandDoesNotExist` to explicitly invoke the error message.
I'm not merging #7141 because I wrote basically all of the code
in this commit, and future blames should go to me if something here
is wrong.
Closes#7141
Co-authored-by: Mia <49593536+mia-pi-git@users.noreply.github.com>
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!
onChatMessage previously took `string | false`, where `false` means
"let the message through". This is a reversal of what `false` usually
means, so this is now updated to `string | void`, which should be
much clearer.
The nullable room refactor made it so there was no longer an easy way
to tell if a command could be used in PMs. This adds it back, as a
property on the handler function itself.
Now that we have properties on handler functions, I also added
`broadcastable` for whether or not the command is broadcastable.
It uses `Function#toString`, which is generally frowned-upon, but it's
well-specified and only happens during startup, so it shouldn't affect
performance after startup.
This also allows us not to need to repeat ourselves or give up
flexibility to have metadata about commands, which I think is worth the
tradeoff of reflection generally.
Half the permissions checks were previously in `user.can`, which is
unintuitive. It's now completely self-contained and should be pretty
readable, now, with `getEffectiveSymbol` and `hasJurisdiction` as
separate functions.
This command should never be used by users.
This is for scripting, like buttons, like:
<button name="send" value="/nofeedback /ionext">
so they don't spam your PMs.
Global punishments like /lock will notify Staff, and admin commands
like /updateserver will log to Staff, but this has been done ad-hoc
in the past.
To handle these cases, this commit introduces new chat-context
functions:
- `this.addGlobalModAction`,
- `this.privateGlobalModAction`
- `this.stafflog`
Other updates:
- the issue where Staff notifications didn't show up until someone talks
has been fixed
- `privateModAction`s in Staff will now be visible in the scrollback
log
- a bunch of commands that should notify Staff but didn't now do
- some typos in modlogs have been fixed
NOTE: This is changes the semantics of `hidenext`/`ionext` from
applying to the next created *battle* to applying to the next
created *search*/*challenge*.
The idea is that throwing `ErrorMessage` will replace needing to pass
`context` variables around (which make it hard to unit test a lot of
chat functions).
I recognize the drawback is that it makes it harder to tell where
chat commands might return from. This might be somewhat alleviated by
a convention such as prefixing everything with `check`
this.checkBroadcastable();
this.checkCan('lock');
I honestly didn't like the old approach of `if (!this.can(...)) return`,
though. It didn't seem very obvious which commands would show error
messages and which needed you to write your own error messages. I think
the new system would at least be clearer about that.
We can also consider things such as some sort of sigil, such as:
!this.checkCan('lock');
There's no other reason to use `!` at the beginning of a line, so I
think this is reasonably unambiguous, although it might take some
time to learn. Also we'd have to screw with eslint.
Another alternative is something all-caps?
this.CHECK_can('lock');
In the end, I still think `this.checkCan('lock')` would be enough, and
I still think it's already an improvement in many ways.
Permissions have gotten out-of-date, so this commit syncs them.
Default permissions are now matched with Main, in particular including
the new & rank as admin (removing the old Leader rank and ~ symbol).
Relevant changes:
- Admin (~) and Leader (&) have been merged into Admin (&)
- The 'ban' permission was split into 'globalban' and 'ban'
- The 'broadcast' permission was renamed 'show' (going forward,
"broadcast" should only refer to the big red/blue/green
announcement bars.)
- Bots no longer have global moderation abilities, making it
easier to give untrustworthy bots the "bot" rank.
They were only ever kept separate because of GlobalRoom. It might be
useful to support rooms that aren't ChatRooms, but we've been chucking
properties into either BasicChatRoom or BasicRoom essentially at
random, so I think it makes sense to wait until we actually have a
use-case for a non-Chat room before carefully deciding which properties
belong where.
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")
- Chat.getImageDimensions and Chat.fitImage now throw if passed things
that aren't image URLs.
- Fix help message if you use /show by itself
- Link to full aize image if image is shrunk
This replaces the old approach with a new "clear everything except a
whitelist" approach, which should overall involve much less code and
lead to fewer bugs of the "the path changed for a module and I forgot
to update the uncache paths" variety.
I considered a lot of other approaches, but they seem to have more
flaws without any advantages in exchange for them. (We moved away
from `uncacheTree` because it only tracks the first require: there's
no way to get a full list of dependents for a module, only its first
dependent.)
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>
Currently, 'hotpatch' and 'lockdown' are admin permissions, and
'console' is a console admin permission. In preparation for the
admin/leader unification, I'm removing the hotpatch permission:
- /memoryusage, /loadbanlist, /adddatacenters, /refreshpage,
/loadbanlist have been moved from 'hotpatch' to 'lockdown'. This
doesn't change anything, I'm just unifying the permission name.
- /updateserver has been moved from 'hotpatch' to 'console'.
/updateserver in combination with either hotpatch or lockdown can be
used for arbitrary code execution, and is approximately as dangerous
as any other console command.
- /hotpatch, /savelearnsets have been moved from 'hotpatch' to
'console'. They're reasonably harmless, but they don't do anything
without console access, so a non-console admin using them is nearly
definitely some sort of mistake.
`user.hasConsoleAccess` now also has a CommandContext function
`this.canUseConsole` to handle its error message.
Mostly, extraneous `<` tags are now correctly detected, with a better tag tokenizer.
I also removed the separate passes for <img> and <button> validation.
Fixes#6685
Thanks PartMan for contributing some ideas.
`user.can` and `user.authAtLeast` now take `Room | BasicChatRoom`
instead of `BasicChatRoom`. It's now significantly less necessary to
cast things to `BasicChatRoom`.
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)
`server/chat-commands.js` is now a directory. It's been split into
`core`, `moderation`, and `admin`. `info` and `roomsettings` from
`chat-plugins` have also moved to `chat-commands`.
Some cleanup:
- Bot commands for inserting HTML into rooms like `/adduhtml` have been
moved from `info` into `admin`.
- `/a` has been renamed `/addline`, for clarity (and also moved from
`info` into `admin`).
- Room management commands like `/createroom` and `/roomintro` were
moved to `room-settings`
- `chat-commands/admin` has been TypeScripted
Command consoles previously would silently fail if you used a
broadcastable command (like `/dt` or `/learn`). They are now let
through, although actually trying to broadcast (like `!dt`) will
still show an error message.