-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessageRouter.go
More file actions
31 lines (25 loc) · 869 Bytes
/
messageRouter.go
File metadata and controls
31 lines (25 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"context"
"encoding/json"
"github.com/bwmarrin/discordgo"
"github.com/go-redis/redis/v8"
)
type lambda func(context.Context, *redis.Client, *pubsubDiscordTopicAddr, discordgo.Message)
// unmashalDiscordMessage is a function that takes a string and returns a
// discordgo.Message
func unmarshalDiscordMessage(msg string) (discordgo.Message, error) {
var dgoMessage discordgo.Message
err := json.Unmarshal([]byte(msg), &dgoMessage)
return dgoMessage, err
}
// publishDiscordMessage is a function that takes a string and
// writes it to destination pubsub channel. It requires a context and a redis
// client.
func publishDiscordMessage(ctx context.Context, rdb *redis.Client, destination, content string) error {
b, err := json.Marshal(content)
if err != nil {
return err
}
return rdb.Publish(ctx, destination, string(b)).Err()
}