mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-20 02:00:49 +00:00
Add subscriber ACL level and make them work on bot commands
This commit is contained in:
parent
f1789a6d82
commit
a72d52d685
5 changed files with 69 additions and 8 deletions
|
@ -201,6 +201,7 @@
|
||||||
"description-help": "What does this command do?",
|
"description-help": "What does this command do?",
|
||||||
"access-level": "Access level",
|
"access-level": "Access level",
|
||||||
"access-everyone": "Everyone",
|
"access-everyone": "Everyone",
|
||||||
|
"access-subscribers": "Subscribers",
|
||||||
"access-vips": "VIPs",
|
"access-vips": "VIPs",
|
||||||
"access-moderators": "Moderators",
|
"access-moderators": "Moderators",
|
||||||
"access-streamer": "Streamer only",
|
"access-streamer": "Streamer only",
|
||||||
|
|
|
@ -35,7 +35,12 @@ interface TwitchModulesConfig {
|
||||||
enable_timers: boolean;
|
enable_timers: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccessLevelType = 'everyone' | 'vip' | 'moderators' | 'streamer';
|
export type AccessLevelType =
|
||||||
|
| 'everyone'
|
||||||
|
| 'subscribers'
|
||||||
|
| 'vip'
|
||||||
|
| 'moderators'
|
||||||
|
| 'streamer';
|
||||||
|
|
||||||
export interface TwitchBotCustomCommand {
|
export interface TwitchBotCustomCommand {
|
||||||
description: string;
|
description: string;
|
||||||
|
|
|
@ -5,7 +5,10 @@ import { useDispatch } from 'react-redux';
|
||||||
import { useModule } from '../../../lib/react-utils';
|
import { useModule } from '../../../lib/react-utils';
|
||||||
import { modules } from '../../../store/api/reducer';
|
import { modules } from '../../../store/api/reducer';
|
||||||
import Modal from '../../components/Modal';
|
import Modal from '../../components/Modal';
|
||||||
import { TwitchBotCustomCommand } from '../../../store/api/types';
|
import {
|
||||||
|
AccessLevelType,
|
||||||
|
TwitchBotCustomCommand,
|
||||||
|
} from '../../../store/api/types';
|
||||||
import Field from '../../components/Field';
|
import Field from '../../components/Field';
|
||||||
|
|
||||||
interface CommandItemProps {
|
interface CommandItemProps {
|
||||||
|
@ -92,6 +95,9 @@ function CommandModal({
|
||||||
const [description, setDescription] = useState(
|
const [description, setDescription] = useState(
|
||||||
initialData?.description ?? '',
|
initialData?.description ?? '',
|
||||||
);
|
);
|
||||||
|
const [accessLevel, setAccessLevel] = useState(
|
||||||
|
initialData?.access_level ?? 'everyone',
|
||||||
|
);
|
||||||
const [response, setResponse] = useState(initialData?.response ?? '');
|
const [response, setResponse] = useState(initialData?.response ?? '');
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
@ -105,7 +111,7 @@ function CommandModal({
|
||||||
description,
|
description,
|
||||||
response,
|
response,
|
||||||
enabled: initialData?.enabled ?? false,
|
enabled: initialData?.enabled ?? false,
|
||||||
access_level: 'everyone',
|
access_level: accessLevel,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -171,10 +177,18 @@ function CommandModal({
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<p className="control">
|
<p className="control">
|
||||||
<span className="select">
|
<span className="select">
|
||||||
<select>
|
<select
|
||||||
|
value={accessLevel}
|
||||||
|
onChange={(ev) =>
|
||||||
|
setAccessLevel(ev.target.value as AccessLevelType)
|
||||||
|
}
|
||||||
|
>
|
||||||
<option value="everyone">
|
<option value="everyone">
|
||||||
{t('twitch.commands.access-everyone')}
|
{t('twitch.commands.access-everyone')}
|
||||||
</option>
|
</option>
|
||||||
|
<option value="subscribers">
|
||||||
|
{t('twitch.commands.access-subscribers')}
|
||||||
|
</option>
|
||||||
<option value="vip">
|
<option value="vip">
|
||||||
{t('twitch.commands.access-vips')}
|
{t('twitch.commands.access-vips')}
|
||||||
</option>
|
</option>
|
||||||
|
|
|
@ -205,3 +205,27 @@ func (b *Bot) Connect() error {
|
||||||
func (b *Bot) WriteMessage(message string) {
|
func (b *Bot) WriteMessage(message string) {
|
||||||
b.Client.Say(b.config.Channel, message)
|
b.Client.Say(b.config.Channel, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserAccessLevel(user irc.User) AccessLevelType {
|
||||||
|
// Check broadcaster
|
||||||
|
if _, ok := user.Badges["broadcaster"]; ok {
|
||||||
|
return ALTStreamer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check mods
|
||||||
|
if _, ok := user.Badges["moderator"]; ok {
|
||||||
|
return ALTModerators
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check VIP
|
||||||
|
if _, ok := user.Badges["vip"]; ok {
|
||||||
|
return ALTVIP
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check subscribers
|
||||||
|
if _, ok := user.Badges["subscriber"]; ok {
|
||||||
|
return ALTSubscribers
|
||||||
|
}
|
||||||
|
|
||||||
|
return ALTEveryone
|
||||||
|
}
|
||||||
|
|
|
@ -15,11 +15,20 @@ type AccessLevelType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ALTEveryone AccessLevelType = "everyone"
|
ALTEveryone AccessLevelType = "everyone"
|
||||||
|
ALTSubscribers AccessLevelType = "subscriber"
|
||||||
ALTVIP AccessLevelType = "vip"
|
ALTVIP AccessLevelType = "vip"
|
||||||
ALTModerators AccessLevelType = "moderators"
|
ALTModerators AccessLevelType = "moderators"
|
||||||
ALTStreamer AccessLevelType = "streamer"
|
ALTStreamer AccessLevelType = "streamer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var accessLevels = map[AccessLevelType]int{
|
||||||
|
ALTEveryone: 0,
|
||||||
|
ALTSubscribers: 1,
|
||||||
|
ALTVIP: 2,
|
||||||
|
ALTModerators: 3,
|
||||||
|
ALTStreamer: 999,
|
||||||
|
}
|
||||||
|
|
||||||
type BotCommandHandler func(bot *Bot, message irc.PrivateMessage)
|
type BotCommandHandler func(bot *Bot, message irc.PrivateMessage)
|
||||||
|
|
||||||
type BotCommand struct {
|
type BotCommand struct {
|
||||||
|
@ -31,6 +40,14 @@ type BotCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdCustom(bot *Bot, cmd string, data BotCustomCommand, message irc.PrivateMessage) {
|
func cmdCustom(bot *Bot, cmd string, data BotCustomCommand, message irc.PrivateMessage) {
|
||||||
|
// Check access level
|
||||||
|
accessLevel := getUserAccessLevel(message.User)
|
||||||
|
|
||||||
|
// Ensure that access level is high enough
|
||||||
|
if accessLevels[accessLevel] < accessLevels[data.AccessLevel] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Add future logic (like counters etc.) here, for now it's just fixed messages
|
// Add future logic (like counters etc.) here, for now it's just fixed messages
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := bot.customTemplates[cmd].Execute(&buf, message)
|
err := bot.customTemplates[cmd].Execute(&buf, message)
|
||||||
|
|
Loading…
Reference in a new issue