Skip to content

Commit

Permalink
feat: add ability to block specific users from submitting clips
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Oct 30, 2023
1 parent 35d9317 commit 9ff5798
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
8 changes: 8 additions & 0 deletions docs/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ Twitch Clip Queue provides a set of commands accessible through Twich chat for m
`!cqunblockchannel <channel>`: Unblock clips of a given channel. Any further clips of this channel will be added to the queue.

> NOTE: if the channel was not previously blocked, then this does nothing.
`!cqblocksubmitter <submitter>`: Block clips submitted by a given user. Any clips submitted by this user will be ignored.

> NOTE: If the submitter is already blocked, then this does nothing.
`!cqunblocksubmitter <submitter>`: Unblock clips submitted by a given user. Any further clips submitted by this user will be added to the queue.

> NOTE: if the submitter was not previously blocked, then this does nothing.
7 changes: 7 additions & 0 deletions src/components/settings/ModerationSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<label>Clips of these channels will not be added to the queue.</label>
</div>
</div>
<div class="cq-form-group">
<label class="cq-form-group-label">Submitters not allowed:</label>
<BaseMultiTagSelect v-model="formSettings.blockedSubmitters" itemName="submitter" />
<div class="cq-text-subtle text-left pl-1 my-2">
<label>Clips submitted by these users will not be added to the queue.</label>
</div>
</div>
<div class="mt-3">
<BaseButton class="mr-2" type="submit" :disabled="!moderation.isModified(formSettings)"
>Save</BaseButton
Expand Down
19 changes: 19 additions & 0 deletions src/stores/__tests__/moderation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,23 @@ describe('moderation.ts', () => {
expect(moderation.blockedChannels.length).toEqual(1)
expect(moderation.blockedChannels).not.toContain('test2')
})

it('can block a submitter from submitting clips', () => {
const moderation = useModeration()
moderation.addBlockedSubmitter('test')
moderation.addBlockedSubmitter('test2')
expect(moderation.blockedSubmitters.length).toEqual(2)
moderation.addBlockedSubmitter('test2')
expect(moderation.blockedSubmitters.length).toEqual(2)
})

it('can unblock a submitter from submitting clips', () => {
const moderation = useModeration()
moderation.addBlockedSubmitter('test')
moderation.addBlockedSubmitter('test2')
expect(moderation.blockedSubmitters.length).toEqual(2)
moderation.removeBlockedSubmitter('Test2')
expect(moderation.blockedSubmitters.length).toEqual(1)
expect(moderation.blockedSubmitters).not.toContain('test2')
})
})
22 changes: 20 additions & 2 deletions src/stores/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export interface Moderation {
hasAutoRemoveClipsEnabled: boolean
// Clips from these channels will not be allowed in the queue.
blockedChannels: string[]
// Users submitting clips will not be allowed in the queue.
blockedSubmitters: string[]
}

export const DEFAULTS: Moderation = {
hasAutoRemoveClipsEnabled: true,
blockedChannels: []
blockedChannels: [],
blockedSubmitters: []
}

export const useModeration = defineStore('moderation', {
Expand All @@ -36,7 +39,10 @@ export const useModeration = defineStore('moderation', {
const blockedChannel = state.blockedChannels.some(
(c) => c.toLowerCase() === clip.channel?.toLowerCase()
)
return !blockedChannel
const blockedSubmitter = state.blockedSubmitters.some(
(s) => s.toLowerCase() === clip.submitter?.toLowerCase()
)
return !blockedChannel && !blockedSubmitter
}
}
},
Expand All @@ -55,6 +61,18 @@ export const useModeration = defineStore('moderation', {
this.blockedChannels = this.blockedChannels.filter(
(c) => c.toLowerCase() !== channel.toLowerCase()
)
},
addBlockedSubmitter(submitter: string) {
// Ignore if the channel is already blocked
if (this.blockedSubmitters.some((s) => s.toLowerCase() === submitter.toLowerCase())) {
return
}
this.blockedSubmitters = [...this.blockedSubmitters, submitter]
},
removeBlockedSubmitter(submitter: string) {
this.blockedSubmitters = this.blockedSubmitters.filter(
(s) => s.toLowerCase() !== submitter.toLowerCase()
)
}
}
})
4 changes: 3 additions & 1 deletion src/utils/__tests__/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ describe('commands.ts', () => {

it.each([
['blockchannel', ['test'], 'addBlockedChannel'],
['unblockchannel', ['test'], 'removeBlockedChannel']
['unblockchannel', ['test'], 'removeBlockedChannel'],
['blocksubmitter', ['test'], 'addBlockedSubmitter'],
['unblocksubmitter', ['test'], 'removeBlockedSubmitter']
])(
'calls the proper clip queue moderation function with params when issued (%s, %s)',
(commandName: string, args: string[], expectedFunctionCall: any) => {
Expand Down
26 changes: 25 additions & 1 deletion src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export enum Command {
PREV = 'prev',
NEXT = 'next',
BLOCK_CHANNEL = 'blockchannel',
UNBLOCK_CHANNEL = 'unblockchannel'
UNBLOCK_CHANNEL = 'unblockchannel',
BLOCK_SUBMITTER = 'blocksubmitter',
UNBLOCK_SUBMITTER = 'unblocksubmitter'
}

interface CommandHelp {
Expand All @@ -36,6 +38,14 @@ const help: Record<Command, CommandHelp> = {
[Command.UNBLOCK_CHANNEL]: {
args: ['channel'],
description: 'Unblock clips from specified channel.'
},
[Command.BLOCK_SUBMITTER]: {
args: ['submitter'],
description: 'Block clips submitted from specified user.'
},
[Command.UNBLOCK_SUBMITTER]: {
args: ['submitter'],
description: 'Unblock clips submitted from specified user.'
}
}

Expand Down Expand Up @@ -86,6 +96,20 @@ export function handleCommand(command: string, ...args: string[]) {
}
break
}
case Command.BLOCK_SUBMITTER: {
if (args[0]) {
const moderation = useModeration()
moderation.addBlockedSubmitter(args[0])
}
break
}
case Command.UNBLOCK_SUBMITTER: {
if (args[0]) {
const moderation = useModeration()
moderation.removeBlockedSubmitter(args[0])
}
break
}
default: {
break
}
Expand Down

1 comment on commit 9ff5798

@vercel
Copy link

@vercel vercel bot commented on 9ff5798 Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.