-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathsetChannelVisibilityAsModerator.ts
61 lines (54 loc) · 2 KB
/
setChannelVisibilityAsModerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
import { flags } from '@oclif/command'
import chalk from 'chalk'
import ExitCodes from '../../ExitCodes'
const CHANNEL_VISIBILITY_CONTEXTS = ['VISIBLE', 'HIDDEN'] as const
export default class SetChannelVisibilityAsModeratorCommand extends ContentDirectoryCommandBase {
static description = 'Set channel visibility as moderator.'
static flags = {
channelId: flags.integer({
char: 'c',
required: true,
description: 'ID of the channel',
}),
status: flags.enum({
char: 's',
options: [...CHANNEL_VISIBILITY_CONTEXTS],
description: 'The visibility status of the channel',
required: true,
}),
rationale: flags.string({
char: 'r',
required: true,
description: 'Reason for changing visibility of channel',
}),
context: ContentDirectoryCommandBase.moderationActionContextFlag,
...ContentDirectoryCommandBase.flags,
}
async run(): Promise<void> {
const { channelId, status, rationale, context } = this.parse(SetChannelVisibilityAsModeratorCommand).flags
// Context
const { privilegeLevel } = await this.getApi().channelById(channelId)
const [actor, address] = await this.getModerationActionActor(context)
// Ensure moderator has required permission
if (!(await this.isModeratorWithRequiredPermission(actor, privilegeLevel, 'HideChannel'))) {
this.error(
`Only content lead or curator with "HideChannel" permission can set visibility of channel ${channelId}!`,
{
exit: ExitCodes.AccessDenied,
}
)
}
await this.requireConfirmation(
`Are you sure you want to set channel visibility ${chalk.magentaBright(
channelId.toString()
)} to ${chalk.magentaBright(status)}?`
)
await this.sendAndFollowNamedTx(await this.getDecodedPair(address), 'content', 'setChannelVisibilityAsModerator', [
actor,
channelId,
status === 'HIDDEN',
rationale,
])
}
}