Add MessageFormatType passing through
Some checks failed
rolling-release / build (push) Has been cancelled
rolling-release / rolling-release (push) Has been cancelled

This commit is contained in:
Dmitrii Okunev
2025-08-15 04:12:37 +01:00
parent 4f59735ea8
commit 1d65b36720
6 changed files with 135 additions and 103 deletions

View File

@@ -15,7 +15,7 @@ type ChatMessage struct {
Username string
MessageID ChatMessageID
Message string
FormatType TextFormatType
MessageFormatType TextFormatType
Paid Money
}

View File

@@ -161,7 +161,7 @@ func (h *ChatHandlerOBSOLETE) sendMessage(
Username: msg.Sender.Slug,
MessageID: streamcontrol.ChatMessageID(msg.ID),
Message: msg.Content,
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
}:
default:
}

View File

@@ -98,7 +98,7 @@ func newChatHandlerIRC(
Username: ev.Sender.Username,
MessageID: streamcontrol.ChatMessageID(ev.ID),
Message: ev.Text, // TODO: investigate if we need ev.IRCMessage.Text
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
}:
default:
logger.Warnf(ctx, "the queue is full, skipping the message")

View File

@@ -101,7 +101,7 @@ func NewChatHandlerSub(
Username: event.UserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: event.Message.Text,
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelAdBreakBegin(func(event twitcheventsub.EventChannelAdBreakBegin, msg twitcheventsub.NotificationMessage) {
@@ -112,7 +112,7 @@ func NewChatHandlerSub(
Username: "Twitch",
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: fmt.Sprintf("%d seconds", event.DurationSeconds),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelBan(func(event twitcheventsub.EventChannelBan, msg twitcheventsub.NotificationMessage) {
@@ -123,7 +123,7 @@ func NewChatHandlerSub(
Username: event.UserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: event.Reason,
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelCheer(func(event twitcheventsub.EventChannelCheer, msg twitcheventsub.NotificationMessage) {
@@ -138,7 +138,7 @@ func NewChatHandlerSub(
Currency: streamcontrol.CurrencyBits,
Amount: float64(event.Bits),
},
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelFollow(func(event twitcheventsub.EventChannelFollow, msg twitcheventsub.NotificationMessage) {
@@ -149,7 +149,7 @@ func NewChatHandlerSub(
Username: event.UserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: "",
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelRaid(func(event twitcheventsub.EventChannelRaid, msg twitcheventsub.NotificationMessage) {
@@ -160,7 +160,7 @@ func NewChatHandlerSub(
Username: event.FromBroadcasterUserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: fmt.Sprintf("%d viewers", event.Viewers),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelShoutoutReceive(func(event twitcheventsub.EventChannelShoutoutReceive, msg twitcheventsub.NotificationMessage) {
@@ -171,7 +171,7 @@ func NewChatHandlerSub(
Username: event.FromBroadcasterUserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: fmt.Sprintf("%d viewers", event.ViewerCount),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelSubscribe(func(event twitcheventsub.EventChannelSubscribe, msg twitcheventsub.NotificationMessage) {
@@ -188,7 +188,7 @@ func NewChatHandlerSub(
Username: event.UserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: strings.Join(description, " "),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelSubscriptionMessage(func(event twitcheventsub.EventChannelSubscriptionMessage, msg twitcheventsub.NotificationMessage) {
@@ -202,7 +202,7 @@ func NewChatHandlerSub(
"%d months (%d in total), tier '%s', message: %s",
event.DurationMonths, event.CumulativeMonths, event.Tier, event.Message.Text,
),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelSubscriptionGift(func(event twitcheventsub.EventChannelSubscriptionGift, msg twitcheventsub.NotificationMessage) {
@@ -216,7 +216,7 @@ func NewChatHandlerSub(
"gift: %d subs, tier '%s'",
event.Total, event.Tier,
),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventStreamOnline(func(event twitcheventsub.EventStreamOnline, msg twitcheventsub.NotificationMessage) {
@@ -227,7 +227,7 @@ func NewChatHandlerSub(
Username: event.BroadcasterUserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: event.StartedAt.Format(time.DateTime),
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventStreamOffline(func(event twitcheventsub.EventStreamOffline, msg twitcheventsub.NotificationMessage) {
@@ -238,7 +238,7 @@ func NewChatHandlerSub(
Username: event.BroadcasterUserName,
MessageID: streamcontrol.ChatMessageID(msg.Metadata.MessageID),
Message: "",
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})
eventSubClient.OnEventChannelChatMessage(func(chatEvent twitcheventsub.EventChannelChatMessage, msg twitcheventsub.NotificationMessage) {
@@ -254,7 +254,7 @@ func NewChatHandlerSub(
Username: chatEvent.ChatterUserName,
MessageID: streamcontrol.ChatMessageID(chatEvent.MessageId),
Message: chatEvent.Message.Text,
FormatType: streamcontrol.TextFormatTypePlain,
MessageFormatType: streamcontrol.TextFormatTypePlain,
})
})

View File

@@ -152,7 +152,7 @@ func (l *ChatListenerOBSOLETE) listenLoop(ctx context.Context) (_err error) {
// in the mean while we we use a soft key for that:
MessageID: streamcontrol.ChatMessageID(fmt.Sprintf("%s/%s", msg.AuthorName, msg.Message)),
Message: text,
FormatType: format,
MessageFormatType: format,
}
}
}

View File

@@ -22,6 +22,22 @@ func ChatMessageGo2GRPC(
UsernameReadable: xstring.ToReadable(event.Username),
MessageID: string(event.MessageID),
Message: event.Message,
MessageFormatType: MessageFormatTypeGo2GRPC(event.MessageFormatType),
}
}
func MessageFormatTypeGo2GRPC(
formatType streamcontrol.TextFormatType,
) streamd_grpc.TextFormatType {
switch formatType {
case streamcontrol.TextFormatTypePlain:
return streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_PLAIN
case streamcontrol.TextFormatTypeMarkdown:
return streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_MARKDOWN
case streamcontrol.TextFormatTypeHTML:
return streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_HTML
default:
return streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_UNDEFINED
}
}
@@ -40,7 +56,23 @@ func ChatMessageGRPC2Go(
Username: event.GetUsername(),
MessageID: streamcontrol.ChatMessageID(event.GetMessageID()),
Message: event.GetMessage(),
MessageFormatType: MessageFormatTypeGRPC2Go(event.GetMessageFormatType()),
},
Platform: streamcontrol.PlatformName(event.GetPlatID()),
}
}
func MessageFormatTypeGRPC2Go(
formatType streamd_grpc.TextFormatType,
) streamcontrol.TextFormatType {
switch formatType {
case streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_PLAIN:
return streamcontrol.TextFormatTypePlain
case streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_MARKDOWN:
return streamcontrol.TextFormatTypeMarkdown
case streamd_grpc.TextFormatType_TEXT_FORMAT_TYPE_HTML:
return streamcontrol.TextFormatTypeHTML
default:
return streamcontrol.TextFormatTypeUndefined
}
}