updateChannelCensorshipStatus.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import chalk from 'chalk'
  3. import ExitCodes from '../../ExitCodes'
  4. import { flags } from '@oclif/command'
  5. export default class UpdateChannelCensorshipStatusCommand extends ContentDirectoryCommandBase {
  6. static description = 'Update Channel censorship status (Censored / Not censored).'
  7. static flags = {
  8. rationale: flags.string({
  9. name: 'rationale',
  10. required: false,
  11. description: 'rationale',
  12. }),
  13. }
  14. static args = [
  15. {
  16. name: 'id',
  17. required: true,
  18. description: 'ID of the Channel',
  19. },
  20. {
  21. name: 'status',
  22. required: false,
  23. description: 'New censorship status of the channel (1 - censored, 0 - not censored)',
  24. },
  25. ]
  26. async run(): Promise<void> {
  27. let {
  28. args: { id, status },
  29. flags: { rationale },
  30. } = this.parse(UpdateChannelCensorshipStatusCommand)
  31. const channel = await this.getApi().channelById(id)
  32. const [actor, address] = await this.getCurationActorByChannel(channel)
  33. if (status === undefined) {
  34. status = await this.simplePrompt({
  35. type: 'list',
  36. message: 'Select new status',
  37. choices: [
  38. { name: 'Censored', value: true },
  39. { name: 'Not censored', value: false },
  40. ],
  41. })
  42. } else {
  43. if (status !== '0' && status !== '1') {
  44. this.error('Invalid status provided. Use "1" for censored and "0" for not censored.', {
  45. exit: ExitCodes.InvalidInput,
  46. })
  47. }
  48. status = !!parseInt(status)
  49. }
  50. if (rationale === undefined) {
  51. rationale = (await this.simplePrompt({
  52. message: 'Please provide the rationale for updating the status',
  53. })) as string
  54. }
  55. await this.sendAndFollowNamedTx(await this.getDecodedPair(address), 'content', 'updateChannelCensorshipStatus', [
  56. actor,
  57. id,
  58. status,
  59. rationale,
  60. ])
  61. console.log(
  62. chalk.green(
  63. `Channel ${chalk.magentaBright(id)} censorship status successfully changed to: ${chalk.magentaBright(
  64. status ? 'Censored' : 'Not censored'
  65. )}!`
  66. )
  67. )
  68. }
  69. }