Commit Graph

275 Commits

Author SHA1 Message Date
Mia
6b4507aba9
Chat: Track slow async commands (#7961) 2021-01-29 08:59:20 -08:00
Kris Johnson
081326b69c
Refactor minor activities (#7766) 2021-01-28 12:12:54 -08:00
Mia
a63fb0074a
CommandContext: Add a method for refreshing html pages (#7666) 2021-01-28 12:10:50 -08:00
Mia
5c9c84c415
Remove User#inRooms and User#games (#7815) 2021-01-28 10:41:35 -08:00
Mia
11e4dcd272
Support using more moderation commands offline (#7742) 2021-01-28 10:41:24 -08:00
Annika
88da40d046
Roomlog: Support getting total linecount (#7885) 2021-01-07 13:10:23 -08:00
Kris Johnson
7bb99e2abb
Add roomsettings for tournaments (#7876)
* Add roomsettings for tournaments

* gar ehseth et hseh

* aeth srth esg
2021-01-05 14:15:57 -08:00
Mia
6ca74b025f Chat: Properly sort filters by priority 2021-01-05 14:24:53 -06:00
Mia
40cc33fcfd
Chat: Add support for private pages (#7877) 2021-01-04 10:15:42 -08:00
Guangcong Luo
c44af3286d Implement Utils.forceWrap
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
2020-12-30 17:41:41 -08:00
Annika
6d92ac8547
Repeats: Support non-time-based repeats (#7518) 2020-12-28 03:39:52 -08:00
Mia
f787625e2c
Translations: Properly ignore non-translation directories (#7826)
* Translations: Properly ignore non-translation directories

* use ids
2020-12-24 10:00:48 -08:00
SirKira(!Uzumaki)
542c28edd1
Allow PMing self with /blockpms on (#7811) 2020-12-21 03:47:24 -08:00
Annika
9a9b06ffc9
Chat: Support specifying priority for chatfilters (#7792) 2020-12-21 03:01:16 -08:00
Guangcong Luo
6ceaed0002 Fix TypeScript error
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.
2020-12-12 19:44:54 +00:00
Mia
b7001afdba
Chat: Add a method for iterating commands (#7722) 2020-12-03 19:37:59 -08:00
Mia
62f358f1d0
Exclude room-specific commands for other rooms in /permissions (#7679) 2020-12-01 07:07:50 -08:00
Kris Johnson
fba68d5be6
Reformat old instances of CommandContext/Room#tr (#7744) 2020-12-01 06:31:55 -08:00
Mia
186677239d
Nicknamefilter: Support hiding nicks from filters (#7751) 2020-12-01 06:21:17 -08:00
Annika
2be851fed4
Chat: Remove unnecessary assertion
It looks like the type checker got smart enough to tell that `Array.isArray` ensures that it's a string. This should fix checks.
2020-11-19 19:54:12 -08:00
Mia
60bda2795f
CommandContext: Move parseCommand into Chat (#7661) 2020-11-11 19:59:38 -08:00
Guangcong Luo
ca5822c63c Set context.parse return value back to any
Sadly, there seems to be an issue with the `no-floating-promises`
linter. I'll revisit this later, but for now, this should fix the build
error.
2020-11-11 09:20:12 +00:00
Guangcong Luo
b9a0d3f494 Fix return signature of context.parse 2020-11-11 03:25:06 +00:00
Mia
b3f549cda2
Chat: Stop sending the message through when a command crashes (#7678) 2020-11-10 14:05:23 -08:00
Mia
850d4a4b9b
Add a command to disable commands (#7655) 2020-11-08 14:39:20 -08:00
Guangcong Luo
fc0e50e8f9 Fix bug in previous commit 2020-11-08 22:26:55 +00:00
Guangcong Luo
1e39e19f00 Refactor chat to use Utils.splitFirst 2020-11-08 18:31:38 +00:00
Guangcong Luo
e55cead3e4 Document context.parseCommand 2020-11-08 18:31:38 +00:00
Mia
71dbb2f466
Support Config.nothrottle (#7637) 2020-11-05 04:52:04 -08:00
Kris Johnson
acbe53ba4a
Modernize the coding style of the OM chat plugin (#7643) 2020-11-05 04:50:05 -08:00
Annika
56506c1801 Fix blocking room invites
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.
2020-11-04 21:37:57 -08:00
Mia
56501355d7
Support ignoring room invites (#7180) 2020-11-03 10:15:17 -08:00
Annika
7f2dec0797
Modlog: Avoid optional properties in ModlogEntry (#7613)
* Modlog: Avoid optional properties in ModlogEntry

* Use a type

* Make IP nullable

* Add NOT NULL constrains

* Fix typo
2020-11-01 14:07:01 -08:00
Guangcong Luo
db4963e49f Improve "click here" error message 2020-11-01 02:06:24 +00:00
Annika
58d8a2af70 Fix API for writing to the global modlog 2020-10-30 16:57:29 -07:00
Mia
6f721e31ff
CommandContext: Add a method for getting roomgames (#7531) 2020-10-28 05:20:33 -07:00
Annika
f2a4798bb8
Chatfilters: Fix reasons displaying as undefined (#7579) 2020-10-27 19:44:53 -07:00
Charlie Kobayashi
4272005e42
sendReplyBox: fix interaction with hidelines (#7577) 2020-10-27 19:32:03 -07:00
Mia
f1f6f21fc1
Connections: Track current chat page (#7522) 2020-10-26 14:43:16 -07:00
Guangcong Luo
e8451f8104 Clean up imports
A lot of our code for child processes doesn't really follow our
original standards. This refactors them back to work the way they
were intended to.
2020-10-24 22:12:35 +01:00
Kris Johnson
57e3d7c185
Add The Studio chat plugin (#7542) 2020-10-24 14:09:43 -07:00
Annika
97713bad33
Validate timeout durations (#7556) 2020-10-22 13:47:26 -07:00
Guangcong Luo
e98024f88f Fix bug in toDurationString precision
Fixes #7554
2020-10-21 19:04:06 -04:00
Guangcong Luo
d6eeb197c1 Improve Chat.toDurationString
- 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")
2020-10-21 13:05:08 +01:00
Mia
ef6cad7c9d
CommandContext: Make requireRoom support specifying a room (#7549) 2020-10-21 04:21:42 -07:00
Guangcong Luo
9d87616176
Add more style linting rules (#7537)
* 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.
2020-10-19 02:42:28 -07:00
Guangcong Luo
0b0cf3733d Fix toTimestamp type signature 2020-10-13 04:40:38 -07:00
Annika
a285c2cf2c
Chat: Propagate promises for loading translations (#7496) 2020-10-09 13:15:50 -07:00
Annika
a3b83ba50b
Translations: Convert JSON to TypeScript (#7493) 2020-10-09 12:03:44 -07:00
Annika
2698153e7c
Quotes: Use readmore blocks for long quotes (#7465) 2020-10-07 11:28:39 -07:00
Leonard Craft III
789d892098
Chat#checkHTML: Ban <iframe> tags (#7476) 2020-10-06 11:16:04 -07:00
Quinton Lee
0094f34e38
Chat: fix CommandContext#filter in PMs
The ChatFilter type already specifies room as `Room | null` so this check should not be needed.
2020-10-04 13:22:57 -05:00
Annika
3fcb8f4e00
Use attributes of CommandContext in Chat.filter (#7461) 2020-10-03 21:30:20 -07:00
Guangcong Luo
523c1a335d
Introduce Chat.oldPlugins (#7434)
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.
2020-09-30 19:45:54 -07:00
Annika
0877f0ae1e
Modlog: Fix entries with an IP address and no user (#7446) 2020-09-30 17:55:41 -07:00
Guangcong Luo
3d68248efa Update to latest eslint
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.
2020-09-29 15:28:08 -07:00
Annika
c2861c2411 Chat: Fix CommandContext#globalModlog 2020-09-28 15:22:25 -07:00
Annika
f1b4e3d43a
Modlog: Refactor to use ModlogEntry objects (#7403) 2020-09-28 11:06:30 -07:00
Mia
ae7a46dd37
Chat: Move forcerename tracking to Monitor and Punishments (#7381) 2020-09-19 02:04:49 -07:00
Annika
59ba8aa876
Chat filters: Support custom redtext (#7392) 2020-09-18 20:38:53 -07:00
Mia
e80f71f648
Chat: Fix Context.checkChat (#7327) 2020-09-16 18:41:30 -07:00
Annika
88558b6ac6
Chat: Always make help commands broadcastable 2020-09-15 16:37:33 -07:00
Guangcong Luo
db449796c9 Document collapseLineBreaksHTML 2020-09-14 01:43:37 -07:00
Annika
87ea9bb431
Add a filter to run code after global punishments (#7362) 2020-09-12 22:33:56 -07:00
Annika
2c6bd4aa5d
Chat plugins: Export plugin state (#7351) 2020-09-10 19:17:00 -07:00
TheMezStrikes
497d746f26
Don't ban autoclose tags without spaces from html (#7341) 2020-09-10 13:36:13 -07:00
Mia
4e4aa2764a
Update AnnotateCommands regexes to account for refactors (#7349) 2020-09-10 13:35:54 -07:00
Annika
1b9e334cd9
Fix visual bug with /hiderank in PMs (#7334) 2020-09-08 00:17:49 -07:00
Guangcong Luo
9b705936b0 Very ugly workaround for /me checkChat bug
There are too many conflicts to revert, so this will have to do for now.
2020-09-06 22:35:28 -04:00
Mia
44fc0123ad
Chat: Refactor CommandContext and PageContext to use ErrorMessage more (#7234) 2020-09-06 00:15:16 -07:00
Mia
1d450461e2
Chat: Show the full command in nonexistent errors (#7286) 2020-08-31 04:13:47 -07:00
Annika
3f000fced2
Do it this way (#7251) 2020-08-26 08:15:55 -07:00
Annika
46d389c3b4
Chat: Make translations not crash on hotpatch (#7263) 2020-08-26 07:48:30 -07:00
Annika
30214cfedd
Chat: Make pages translatable (#7258) 2020-08-26 03:34:56 -07:00
Guangcong Luo
e14485656f Implement a basic /hiderank
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.
2020-08-22 07:20:26 -07:00
Guangcong Luo
2878793964 Revert accidental merge of /hiderank code
`/hiderank` code was accidentally merged into #7078

This fully backs out its code.
2020-08-22 06:57:24 -07:00
Annika
44d369ca8a
Allow users to set their own language and translate helptickets (#7220) 2020-08-19 00:21:51 -07:00
PartMan
86e8a9159e
Slight HTML Button Improvements (#7217)
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>
2020-08-18 13:56:03 -07:00
Guangcong Luo
0ca4ed2839 Improve private command support
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>
2020-08-16 13:21:07 -07:00
Mia
0f12d8232c
Show error when using ! on a non-broadcastable command (#7209) 2020-08-16 11:27:06 -07:00
Kris Johnson
5e255012bc
Add a 'bst' property to Species (#7138) 2020-08-12 12:06:09 -07:00
Guangcong Luo
a315c93836 Switch to using import type
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!
2020-08-09 08:07:00 -05:00
Guangcong Luo
ec93b354bc Fix PM support
(Broken by parseCommand refactor)
2020-08-06 22:21:48 -04:00
Annika
f563252418
Modlog: Fix bugs and support hotpatching (#7163) 2020-08-06 22:05:13 -04:00
Annika
f34ffa9e74
Refactor Modlog into one file (#7127) 2020-08-06 00:39:37 -07:00
Guangcong Luo
9b3a986ef4 Refactor PageContext
Now shows a better error for not-found pages.
2020-08-06 00:25:21 -07:00
Annika
8287cbc7fb
Remove User#authAtLeast and add more sysop bypasses (#7046) 2020-08-06 00:12:30 -07:00
Mia
647d5af76f
Add a filter for auto-answering questions in the Help room (#7100) 2020-08-05 23:44:46 -07:00
Annika
ae11a699a6
Add a BasicRoom#tr method (#7143) 2020-08-05 19:14:41 -07:00
Mia
47d00bf912
Support per-command permissions for sub-commands (#7142) 2020-08-04 03:01:17 -07:00
Guangcong Luo
80c669641a Refactor context.splitCommand
It no longer has side effects, which should make it easier to use for
other use cases.
2020-08-04 02:54:21 -07:00
Mia
50127f6a7a
Make !commands hidetextable (#7137) 2020-08-03 19:34:35 -07:00
Peach
27513b7ff1
Fix chat commands typing (#7106) 2020-08-01 16:05:27 -07:00
Annika
cd85cd7a9d
Hosts & IPTools: Refactor to remove hardcoded ranges (#7078) 2020-07-29 23:04:50 -07:00
Guangcong Luo
328ba42a12 Change onChatMessage API to use void return
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.
2020-07-29 15:01:04 -07:00
Mia
94fff9d496
Support customizing permissions per-room (#6883) 2020-07-29 00:22:03 -07:00
Peach
f2bfe2538c
Make sendhtmlpage perms more strict, refactor perm checks (#7044) 2020-07-25 23:31:28 -07:00
Annika
74e13815af
Modlog: Mark room tournaments in modlog (#7062) 2020-07-25 21:32:01 -07:00
Guangcong Luo
7d7db34c1d Support Chat.ErrorMessage in async commands
Fixes #7018
2020-07-18 16:33:22 -07:00
Lusamine
3a2ca90040
Minor cleanup of global demotion messages (#7011) 2020-07-17 01:17:36 -07:00
Guangcong Luo
2e9328eada Support annotating chat commands
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.
2020-07-13 00:55:23 -07:00
Guangcong Luo
52f0096c30 Refactor Auth.hasPermission
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.
2020-07-13 00:55:23 -07:00
Annika
b590d3c907
Add /noreply command (#6953)
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.
2020-07-10 22:01:15 -07:00
Guangcong Luo
9fe5a0e063 Improve "Message can't be blank" error
It was previously a popup, but there's no need for that anymore. An
`errorReply` is much friendlier.
2020-07-10 05:06:02 -07:00
Guangcong Luo
faab60a618 Unify command logging code
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
2020-07-07 18:51:29 -07:00
Guangcong Luo
d6de3ce6eb Fix typo in HTML scripted button validator 2020-07-07 21:27:04 -04:00
Kirk Scheibelhut
eea2196280
Server side changes to support persistent user settings and privacy changes (#6947)
NOTE: This is changes the semantics of `hidenext`/`ionext` from
applying to the next created *battle* to applying to the next
created *search*/*challenge*.
2020-07-06 21:18:38 -07:00
Guangcong Luo
c124720885
Support throwing error messages (#6946)
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.
2020-07-06 14:07:02 -07:00
Mia
4997a47314
Commands: Allow the room parameter to be null (#6948)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-07-05 14:25:09 -07:00
Guangcong Luo
d7ba455e2b Update permissions
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.
2020-07-03 17:32:49 -04:00
Guangcong Luo
f16849eda3 Support addModAction/privateModAction in PMs 2020-07-03 01:18:17 -04:00
Guangcong Luo
26615490f7 Merge BasicChatRoom and BasicRoom
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.
2020-07-02 18:54:02 -07:00
Guangcong Luo
ba1730900f Support comments in /roomintro etc 2020-07-02 14:34:53 -04:00
Guangcong Luo
46c9afa2f3
"Remove" the global room (#6885)
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")
2020-07-02 11:31:34 -07:00
Guangcong Luo
6af875af8b Improve RoomPermission/GlobalPermission checks
Global permissions can no longer be used as room permissions. Instead,
the two are entirely separate lists, with only a few permissions in
both lists.
2020-06-21 03:53:06 -07:00
Guangcong Luo
ee6e43b552 Strongly type RoomPermission and GlobalPermission
`user-groups.ts` now tracks the list of possible values for
`RoomPermission` and `GlobalPermission` in a const.
2020-06-21 01:43:27 -07:00
Mia
d2b255b934
/eval: Log in dev room and broadcast (#6871)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-06-18 23:28:15 -07:00
Guangcong Luo
ba53a2831c Fix bugs in /show
- 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
2020-06-17 21:11:52 -04:00
Charlie Kobayashi
95b29974fd
Fix server crash from overlength posts (#6847)
(Server would crash and be unable to handle any further inputs from users)

Byproduct of #6745
2020-06-16 19:42:55 -07:00
Mia
6c97866f83
Add commands to show media in chat (#6745) 2020-06-16 14:40:10 -07:00
Guangcong Luo
e0f97dcf6b Replace Chat.uncache* with Utils.clearRequireCache
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.)
2020-06-12 22:02:32 -07:00
Austin Couturier
c9b2b9dbf2
Change |pm|~ to |pm|& (#6827) 2020-06-10 21:53:36 -07:00
Guangcong Luo
140f4ad936 Support /forceroompromote
Previously, forcepromotes were done with a !!! sigil, which was
kind of silly. They now use a command starting with "force", as
is standard.
2020-06-10 11:23:20 -04:00
Mia
6839a1f4db
Add a library for utility functions (#6817) 2020-06-09 22:06:43 -07:00
Mia
15fed24b40
Refactor auth and room.settings (#6777)
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>
2020-06-09 08:22:25 -07:00
Guangcong Luo
08420c7feb Reassign hotpatch permissions
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.
2020-06-06 07:44:31 -07:00
Mia
f52b456b9a
Chat: Make HTML pages display an error on crash (#6782) 2020-06-02 09:02:48 -07:00
Guangcong Luo
6a8e166af1 Improve broadcast (!command) errors 2020-05-29 04:22:40 -04:00
PartMan
10a50d68a5
Allow scripted buttons to PM bots (#6724) 2020-05-22 18:21:48 -07:00
PartMan
d1394a6346
Add case insensitivity to Scripted Buttons (#6711) 2020-05-17 14:50:16 -07:00
Guangcong Luo
88365abc4a Fix overzealous HTML validator
I forgot h1-h6 could have numbers in them...
2020-05-16 11:55:14 -04:00
Guangcong Luo
1d6d8f73da Refactor HTML validator
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.
2020-05-16 10:51:45 -04:00
fart
160a737979
escapeHTML when notifications blocked (#6644) 2020-05-02 15:27:44 -07:00
Guangcong Luo
1dada44a2a Support server/chat-plugins/private as symlink 2020-04-25 15:51:11 -04:00
Guangcong Luo
a049d85a98 Fix build errors from TypeScript update
I'm not entirely sure why these two errors are cropping up now, but
they are.

The "thenable" one seems to be a bug, but in what?
2020-04-17 23:00:28 -07:00
Kris Johnson
994fc60aed
Rename Template to Species (#6478) 2020-03-25 23:29:27 -07:00
Guangcong Luo
7de51956c5 Change BasicChatRoom to Room in some types
`user.can` and `user.authAtLeast` now take `Room | BasicChatRoom`
instead of `BasicChatRoom`. It's now significantly less necessary to
cast things to `BasicChatRoom`.
2020-03-15 19:52:59 -07:00
Guangcong Luo
35aad974f8 Implement Chat.normalize 2020-03-13 22:30:17 -04:00
Guangcong Luo
647ba61a46 Turn on prefer-regex-exec in eslint 2020-03-07 13:39:02 -08:00
Guangcong Luo
125fe31d06 Improve eslintrc
Fixed some more code style, allowing these rules to be enabled:

- `comma-dangle`
- `function-paren-newline`
- `member-delimiter-style`
- `no-eval`
- `no-fallthrough`
- `no-misused-promises`
- `no-unused-vars`
- `operator-linebreak`
2020-03-06 22:35:55 -08:00
Waleed Hassan
8aa4f053bb
Use optional chaining and linter improvements (#6422)
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)
2020-03-06 11:44:32 -08:00
Guangcong Luo
b21c9047e2
Migrate to typescript-eslint (#6342) 2020-03-05 08:33:06 -08:00
Kris Johnson
9aaab2c57b
Typescript Help Tickets and Modlog and fix warnings (#6352) 2020-02-12 21:48:03 -08:00
Ben Davies
e8c8e0d9bd Add CommandContext#shouldBroadcast and fix !code permission checks (#6198) 2019-12-28 16:26:50 +09:00
whales
0b9d8dd109 Support declarative roomsettings syntax (#6119) 2019-12-06 23:16:55 +09:00
whales
f7d5cefc7d Refactor tournament plugin loading (#6118) 2019-11-30 17:53:01 +13:00
Guangcong Luo
23f9bfa1b7
Split up server/chat-commands/ (#5943)
`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
2019-11-15 11:12:54 +13:00
Guangcong Luo
c40a7d2fb2 Allow broadcastable commands in command console
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.
2019-11-11 02:13:48 +13:00
Astrid Halberkamp
a3244a7449
Fix URL detection in usernames 2019-11-10 13:23:11 +01:00
Waleed Hassan
28e870c4fb Server: Use readonly where appropriate (#5902) 2019-10-21 16:12:32 +10:30