mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[core] Add ban
, clearchat
and timeout
events
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
9eb6876305
commit
a1741fbf53
3 changed files with 82 additions and 0 deletions
|
@ -3,7 +3,9 @@ package main
|
||||||
func ptrStr(s string) *string { return &s }
|
func ptrStr(s string) *string { return &s }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
eventTypeBan = ptrStr("ban")
|
||||||
eventTypeBits = ptrStr("bits")
|
eventTypeBits = ptrStr("bits")
|
||||||
|
eventTypeClearChat = ptrStr("clearchat")
|
||||||
eventTypeJoin = ptrStr("join")
|
eventTypeJoin = ptrStr("join")
|
||||||
eventTypeHost = ptrStr("host")
|
eventTypeHost = ptrStr("host")
|
||||||
eventTypePart = ptrStr("part")
|
eventTypePart = ptrStr("part")
|
||||||
|
@ -13,6 +15,7 @@ var (
|
||||||
eventTypeSub = ptrStr("sub")
|
eventTypeSub = ptrStr("sub")
|
||||||
eventTypeSubgift = ptrStr("subgift")
|
eventTypeSubgift = ptrStr("subgift")
|
||||||
eventTypeSubmysterygift = ptrStr("submysterygift")
|
eventTypeSubmysterygift = ptrStr("submysterygift")
|
||||||
|
eventTypeTimeout = ptrStr("timeout")
|
||||||
eventTypeWhisper = ptrStr("whisper")
|
eventTypeWhisper = ptrStr("whisper")
|
||||||
|
|
||||||
eventTypeTwitchCategoryUpdate = ptrStr("category_update")
|
eventTypeTwitchCategoryUpdate = ptrStr("category_update")
|
||||||
|
@ -21,6 +24,9 @@ var (
|
||||||
eventTypeTwitchTitleUpdate = ptrStr("title_update")
|
eventTypeTwitchTitleUpdate = ptrStr("title_update")
|
||||||
|
|
||||||
knownEvents = []*string{
|
knownEvents = []*string{
|
||||||
|
eventTypeBan,
|
||||||
|
eventTypeBits,
|
||||||
|
eventTypeClearChat,
|
||||||
eventTypeJoin,
|
eventTypeJoin,
|
||||||
eventTypeHost,
|
eventTypeHost,
|
||||||
eventTypePart,
|
eventTypePart,
|
||||||
|
@ -30,6 +36,7 @@ var (
|
||||||
eventTypeSub,
|
eventTypeSub,
|
||||||
eventTypeSubgift,
|
eventTypeSubgift,
|
||||||
eventTypeSubmysterygift,
|
eventTypeSubmysterygift,
|
||||||
|
eventTypeTimeout,
|
||||||
eventTypeWhisper,
|
eventTypeWhisper,
|
||||||
|
|
||||||
eventTypeTwitchCategoryUpdate,
|
eventTypeTwitchCategoryUpdate,
|
||||||
|
|
45
irc.go
45
irc.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Luzifer/twitch-bot/plugins"
|
"github.com/Luzifer/twitch-bot/plugins"
|
||||||
"github.com/Luzifer/twitch-bot/twitch"
|
"github.com/Luzifer/twitch-bot/twitch"
|
||||||
|
@ -116,6 +117,12 @@ func (i ircHandler) Handle(c *irc.Client, m *irc.Message) {
|
||||||
})
|
})
|
||||||
go i.ExecuteJoins(config.Channels)
|
go i.ExecuteJoins(config.Channels)
|
||||||
|
|
||||||
|
case "CLEARCHAT":
|
||||||
|
// CLEARCHAT (Twitch Commands)
|
||||||
|
// Purge a user’s messages, typically after a user is banned from
|
||||||
|
// chat or timed out.
|
||||||
|
i.handleClearChat(m)
|
||||||
|
|
||||||
case "JOIN":
|
case "JOIN":
|
||||||
// JOIN (Default IRC Command)
|
// JOIN (Default IRC Command)
|
||||||
// User enters the channel, might be triggered multiple times
|
// User enters the channel, might be triggered multiple times
|
||||||
|
@ -133,6 +140,7 @@ func (i ircHandler) Handle(c *irc.Client, m *irc.Message) {
|
||||||
i.handlePart(m)
|
i.handlePart(m)
|
||||||
|
|
||||||
case "PING":
|
case "PING":
|
||||||
|
// PING (Default IRC Command)
|
||||||
// Handled by the library, just here to prevent trace-logging every ping
|
// Handled by the library, just here to prevent trace-logging every ping
|
||||||
|
|
||||||
case "PRIVMSG":
|
case "PRIVMSG":
|
||||||
|
@ -184,6 +192,43 @@ func (ircHandler) getChannel(m *irc.Message) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i ircHandler) handleClearChat(m *irc.Message) {
|
||||||
|
seconds, secondsErr := strconv.Atoi(string(m.Tags["ban-duration"]))
|
||||||
|
targetUserID, hasTargetUserID := m.Tags.GetTag("target-user-id")
|
||||||
|
|
||||||
|
var (
|
||||||
|
evt *string
|
||||||
|
fields = plugins.FieldCollection{
|
||||||
|
"channel": i.getChannel(m), // Compatibility to plugins.DeriveChannel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case secondsErr == nil && hasTargetUserID:
|
||||||
|
// User & Duration = Timeout
|
||||||
|
evt = eventTypeTimeout
|
||||||
|
fields["duration"] = time.Duration(seconds) * time.Second
|
||||||
|
fields["seconds"] = seconds
|
||||||
|
fields["target_id"] = targetUserID
|
||||||
|
fields["target_name"] = m.Trailing()
|
||||||
|
log.WithFields(log.Fields(fields)).Info("User was timeouted")
|
||||||
|
|
||||||
|
case hasTargetUserID:
|
||||||
|
// User w/o Duration = Ban
|
||||||
|
evt = eventTypeBan
|
||||||
|
fields["target_id"] = targetUserID
|
||||||
|
fields["target_name"] = m.Trailing()
|
||||||
|
log.WithFields(log.Fields(fields)).Info("User was banned")
|
||||||
|
|
||||||
|
default:
|
||||||
|
// No User = /clear
|
||||||
|
evt = eventTypeClearChat
|
||||||
|
log.WithFields(log.Fields(fields)).Info("Chat was cleared")
|
||||||
|
}
|
||||||
|
|
||||||
|
go handleMessage(i.c, m, evt, fields)
|
||||||
|
}
|
||||||
|
|
||||||
func (i ircHandler) handleJoin(m *irc.Message) {
|
func (i ircHandler) handleJoin(m *irc.Message) {
|
||||||
go handleMessage(i.c, m, eventTypeJoin, nil)
|
go handleMessage(i.c, m, eventTypeJoin, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
# Available Events
|
# Available Events
|
||||||
|
|
||||||
|
## `ban`
|
||||||
|
|
||||||
|
Moderator action caused a user to be banned from chat.
|
||||||
|
|
||||||
|
Fields:
|
||||||
|
|
||||||
|
- `channel` - The channel the event occurred in
|
||||||
|
- `target_id` - The ID of the user being banned
|
||||||
|
- `target_name` - The login-name of the user being banned
|
||||||
|
|
||||||
## `bits`
|
## `bits`
|
||||||
|
|
||||||
User spent bits in the channel. The full message is available like in a normal chat message, additionally the `{{ .bits }}` field is added with the total amount of bits spent.
|
User spent bits in the channel. The full message is available like in a normal chat message, additionally the `{{ .bits }}` field is added with the total amount of bits spent.
|
||||||
|
@ -19,6 +29,14 @@ Fields:
|
||||||
- `category` - The name of the new game / category
|
- `category` - The name of the new game / category
|
||||||
- `channel` - The channel the event occurred in
|
- `channel` - The channel the event occurred in
|
||||||
|
|
||||||
|
## `clearchat`
|
||||||
|
|
||||||
|
Moderator action caused chat to be cleared.
|
||||||
|
|
||||||
|
Fields:
|
||||||
|
|
||||||
|
- `channel` - The channel the event occurred in
|
||||||
|
|
||||||
## `join`
|
## `join`
|
||||||
|
|
||||||
User joined the channel-chat. This is **NOT** an indicator they are viewing, the event is **NOT** reliably sent when the user really joined the chat. The event will be sent with some delay after they join the chat and is sometimes repeated multiple times during their stay. So **DO NOT** use this to greet users!
|
User joined the channel-chat. This is **NOT** an indicator they are viewing, the event is **NOT** reliably sent when the user really joined the chat. The event will be sent with some delay after they join the chat and is sometimes repeated multiple times during their stay. So **DO NOT** use this to greet users!
|
||||||
|
@ -116,6 +134,18 @@ Fields:
|
||||||
- `plan` - The sub-plan they are using (`1000` = T1, `2000` = T2, `3000` = T3, `Prime`)
|
- `plan` - The sub-plan they are using (`1000` = T1, `2000` = T2, `3000` = T3, `Prime`)
|
||||||
- `username` - The login-name of the user who gifted the subscription
|
- `username` - The login-name of the user who gifted the subscription
|
||||||
|
|
||||||
|
## `timeout`
|
||||||
|
|
||||||
|
Moderator action caused a user to be timeouted from chat.
|
||||||
|
|
||||||
|
Fields:
|
||||||
|
|
||||||
|
- `channel` - The channel the event occurred in
|
||||||
|
- `duration` - The timeout duration (`time.Duration`, nanoseconds)
|
||||||
|
- `seconds` - The timeout duration (`int`, seconds)
|
||||||
|
- `target_id` - The ID of the user being timeouted
|
||||||
|
- `target_name` - The login-name of the user being timeouted
|
||||||
|
|
||||||
## `title_update`
|
## `title_update`
|
||||||
|
|
||||||
The current title for the channel was changed. (This event has some delay to the real category change!)
|
The current title for the channel was changed. (This event has some delay to the real category change!)
|
||||||
|
|
Loading…
Reference in a new issue