1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +00:00

Remove toggle for chat keys

This commit is contained in:
Ash Keel 2022-01-21 10:08:51 +01:00
parent c9cc780bdc
commit b078f6d8c0
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
5 changed files with 33 additions and 76 deletions

View file

@ -95,10 +95,7 @@
"bot-info-header": "Bot account info", "bot-info-header": "Bot account info",
"bot-settings-copy": "A bot can interact with chat messages and provide extra events for the platform (chat events, some notifications) but requires access to a Twitch account. You can use your own or make a new one (if enabled on your main account, you can re-use the same email for your second account!)", "bot-settings-copy": "A bot can interact with chat messages and provide extra events for the platform (chat events, some notifications) but requires access to a Twitch account. You can use your own or make a new one (if enabled on your main account, you can re-use the same email for your second account!)",
"bot-chat-header": "Chat logging", "bot-chat-header": "Chat logging",
"bot-chat-keys": "Enable chat logging", "bot-chat-history": "How many messages to keep in history (0 to disable)"
"bot-chat-history": "How many messages to keep in history",
"bot-chat-history-suffix": "messages",
"bot-chat-history-desc": "Chat logging allows for pages and modules to read messages from chat. It's recommended to keep chat logging enabled with a reasonable history size (eg. 6)"
}, },
"botcommands": { "botcommands": {
"title": "Bot commands", "title": "Bot commands",

View file

@ -21,7 +21,6 @@ interface TwitchBotConfig {
username: string; username: string;
oauth: string; oauth: string;
channel: string; channel: string;
chat_keys: boolean;
chat_history: number; chat_history: number;
} }

View file

@ -157,65 +157,25 @@ function TwitchBotSettings() {
<SectionHeader> <SectionHeader>
{t('pages.twitch-settings.bot-chat-header')} {t('pages.twitch-settings.bot-chat-header')}
</SectionHeader> </SectionHeader>
<TextBlock>{t('pages.twitch-settings.bot-chat-history-desc')}</TextBlock> <Field size="fullWidth">
<Field>
<FlexRow spacing={1}>
<Checkbox
disabled={!active || status?.type === 'pending'}
checked={botConfig?.chat_keys ?? false}
onCheckedChange={(ev) =>
dispatch(
apiReducer.actions.twitchBotConfigChanged({
...botConfig,
chat_keys: !!ev,
}),
)
}
id="bot-chat-keys"
>
<CheckboxIndicator>{active && <CheckIcon />}</CheckboxIndicator>
</Checkbox>
<Label htmlFor="bot-chat-keys">
{t('pages.twitch-settings.bot-chat-keys')}
</Label>
</FlexRow>
</Field>
<Field size="vertical">
<Label htmlFor="bot-chat-history"> <Label htmlFor="bot-chat-history">
{t('pages.twitch-settings.bot-chat-history')} {t('pages.twitch-settings.bot-chat-history')}
</Label> </Label>
<FlexRow <InputBox
css={{ type="number"
justifyContent: 'flex-start', id="bot-chat-history"
gap: '0.8rem', required={active}
backgroundColor: '$gray6', disabled={!active || status?.type === 'pending'}
borderRadius: '5px', value={botConfig?.chat_history ?? ''}
paddingRight: '0.8rem', onChange={(ev) =>
}} dispatch(
> apiReducer.actions.twitchBotConfigChanged({
<InputBox ...botConfig,
type="number" chat_history: ev.target.value,
id="bot-chat-history" }),
required={active} )
disabled={!active || status?.type === 'pending'} }
value={botConfig?.chat_history ?? ''} />
css={{
appearance: 'textfield',
width: '4rem',
textAlign: 'center',
}}
onChange={(ev) =>
dispatch(
apiReducer.actions.twitchBotConfigChanged({
...botConfig,
chat_history: ev.target.value,
}),
)
}
/>
{t('pages.twitch-settings.bot-chat-history-suffix')}
</FlexRow>
</Field> </Field>
<SaveButton status={status} /> <SaveButton status={status} />
</form> </form>

View file

@ -108,15 +108,13 @@ func NewBot(api *Client, config BotConfig) *Bot {
} }
bot.mu.Unlock() bot.mu.Unlock()
if bot.config.EnableChatKeys { bot.api.db.PutJSON(ChatEventKey, message)
bot.api.db.PutJSON(ChatEventKey, message) if bot.config.ChatHistory > 0 {
if bot.config.ChatHistory > 0 { if len(bot.chatHistory) >= bot.config.ChatHistory {
if len(bot.chatHistory) >= bot.config.ChatHistory { bot.chatHistory = bot.chatHistory[len(bot.chatHistory)-bot.config.ChatHistory+1:]
bot.chatHistory = bot.chatHistory[len(bot.chatHistory)-bot.config.ChatHistory+1:]
}
bot.chatHistory = append(bot.chatHistory, message)
bot.api.db.PutJSON(ChatHistoryKey, bot.chatHistory)
} }
bot.chatHistory = append(bot.chatHistory, message)
bot.api.db.PutJSON(ChatHistoryKey, bot.chatHistory)
} }
if bot.Timers != nil { if bot.Timers != nil {
@ -156,11 +154,15 @@ func NewBot(api *Client, config BotConfig) *Bot {
} }
// Load custom commands // Load custom commands
api.db.GetJSON(CustomCommandsKey, &bot.customCommands) err = api.db.GetJSON(CustomCommandsKey, &bot.customCommands)
err = bot.updateTemplates()
if err != nil { if err != nil {
bot.logger.WithError(err).Error("failed to load custom commands") bot.logger.WithError(err).Error("failed to load custom commands")
} }
err = bot.updateTemplates()
if err != nil {
bot.logger.WithError(err).Error("failed to parse custom commands")
}
go api.db.Subscribe(context.Background(), bot.updateCommands, CustomCommandsKey) go api.db.Subscribe(context.Background(), bot.updateCommands, CustomCommandsKey)
go api.db.Subscribe(context.Background(), bot.handleWriteMessageRPC, WriteMessageRPC) go api.db.Subscribe(context.Background(), bot.handleWriteMessageRPC, WriteMessageRPC)

View file

@ -12,11 +12,10 @@ type Config struct {
const BotConfigKey = "twitch/bot-config" const BotConfigKey = "twitch/bot-config"
type BotConfig struct { type BotConfig struct {
Username string `json:"username"` Username string `json:"username"`
Token string `json:"oauth"` Token string `json:"oauth"`
Channel string `json:"channel"` Channel string `json:"channel"`
EnableChatKeys bool `json:"chat_keys"` ChatHistory int `json:"chat_history"`
ChatHistory int `json:"chat_history"`
} }
const ChatEventKey = "twitch/ev/chat-message" const ChatEventKey = "twitch/ev/chat-message"