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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package irc
import (
"context"
"flag"
"net/http"
"github.com/twitchtv/twirp"
"google.golang.org/protobuf/types/known/emptypb"
xinternal "within.website/x/internal"
"within.website/x/proto/external/jsonfeed"
"within.website/x/proto/mimi/announce"
)
var (
discordPOSSEAnnounceChannel = flag.String("discord-posse-announce-channel", "1191450220731584532", "Discord channel to announce in")
ircAnnouncerUsername = flag.String("irc-announcer-username", "mimi", "IRC announcer HTTP username")
ircAnnouncerPassword = flag.String("irc-announcer-password", "", "IRC announcer HTTP password")
)
func (m *Module) RegisterHTTP(mux *http.ServeMux) {
var h http.Handler = announce.NewAnnounceServer(&AnnounceService{Module: m})
h = xinternal.PasswordMiddleware(*ircAnnouncerUsername, *ircAnnouncerPassword, h)
var postH http.Handler = announce.NewPostServer(&PostService{Module: m})
postH = xinternal.PasswordMiddleware(*ircAnnouncerUsername, *ircAnnouncerPassword, postH)
mux.Handle(announce.AnnouncePathPrefix, h)
mux.Handle(announce.PostPathPrefix, postH)
}
type AnnounceService struct {
*Module
}
type State struct {
Announced map[string]struct{}
}
func (a *AnnounceService) Announce(ctx context.Context, msg *jsonfeed.Item) (*emptypb.Empty, error) {
a.conn.Privmsgf(*ircChannel, "New article :: %s :: %s", msg.Title, msg.Url)
if _, err := a.dg.ChannelMessageSend(*discordPOSSEAnnounceChannel, msg.GetUrl()); err != nil {
return nil, twirp.InternalErrorWith(err).WithMeta("step", "discord")
}
return &emptypb.Empty{}, nil
}
|