1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-16 16:30:09 +00:00
Tims-Chat/files_wcf/js/Bastelstu.be/Chat/Command/_Unsuspension.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-08-16 22:30:59 +00:00
/*
2024-01-13 20:03:36 +00:00
* Copyright (c) 2010-2024 Tim Düsterhus.
2018-08-16 22:30:59 +00:00
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
2024-01-13 20:03:36 +00:00
* Change Date: 2028-01-13
2018-08-16 22:30:59 +00:00
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3
* or later of the General Public License.
*/
define(['../Command', '../Parser'], function (Command, Parser) {
'use strict'
const DEPENDENCIES = ['ProfileStore']
class Unsuspension extends Command {
constructor(profileStore, id) {
super(id)
this.profileStore = profileStore
}
getParameterParser() {
const Globally = Parser.C.string('global').thenLeft(
Parser.C.string('ly').opt()
2020-11-01 16:41:19 +00:00
)
2018-08-16 22:30:59 +00:00
return Parser.Username.then(
Parser.Whitespace.rep()
.thenRight(Globally.thenReturns(true))
.or(Parser.F.returns(false))
).map(([username, globally]) => {
return { username, globally }
})
}
*autocomplete(parameterString) {
const usernameDone = Parser.Username.thenLeft(
Parser.Whitespace.rep()
).map((username) => `"${username.replace(/"/g, '""')}"`)
const globallyDone = usernameDone
.then(Parser.C.string('global').thenLeft(Parser.C.string('ly').opt()))
.thenLeft(Parser.Whitespace.rep())
const usernameCheck = usernameDone.parse(
Parser.Streams.ofString(parameterString)
2020-11-01 16:41:19 +00:00
)
2018-08-16 22:30:59 +00:00
if (usernameCheck.isAccepted()) {
const globallyCheck = globallyDone.parse(
Parser.Streams.ofString(parameterString)
2020-11-01 16:41:19 +00:00
)
2018-08-16 22:30:59 +00:00
let prefix, rest
if (globallyCheck.isAccepted()) {
prefix = parameterString.substring(0, globallyCheck.offset)
rest = parameterString.substring(globallyCheck.offset)
} else {
prefix = parameterString.substring(0, usernameCheck.offset)
rest = parameterString.substring(usernameCheck.offset)
}
if (!globallyCheck.isAccepted() && 'globally'.startsWith(rest)) {
yield `${prefix}globally `
}
}
for (const userID of this.profileStore.getLastActivity()) {
const user = this.profileStore.get(userID)
if (!user.username.startsWith(parameterString)) continue
yield `"${user.username.replace(/"/g, '""')}" `
}
}
}
Unsuspension.DEPENDENCIES = DEPENDENCIES
return Unsuspension
})