summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-17 21:49:45 +0100
committerGitHub <noreply@github.com>2019-02-17 21:49:45 +0100
commit0bcb0b882f8f49d9ae889165dc4478d1168e1f25 (patch)
treee9c23f4f07c46081e12f11e284ec5a39928138ab
parent4525fa31aa6ea595c93994b05a3a042965249100 (diff)
downloadmatterbridge-msglm-0bcb0b882f8f49d9ae889165dc4478d1168e1f25.tar.gz
matterbridge-msglm-0bcb0b882f8f49d9ae889165dc4478d1168e1f25.tar.bz2
matterbridge-msglm-0bcb0b882f8f49d9ae889165dc4478d1168e1f25.zip
Support join/leaves from discord. Closes #654 (#721)
-rw-r--r--bridge/discord/discord.go2
-rw-r--r--bridge/discord/handlers.go42
-rw-r--r--gateway/gateway.go12
3 files changed, 56 insertions, 0 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index d74ed6a6..bc33796c 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -75,6 +75,8 @@ func (b *Bdiscord) Connect() error {
b.c.AddHandler(b.memberUpdate)
b.c.AddHandler(b.messageUpdate)
b.c.AddHandler(b.messageDelete)
+ b.c.AddHandler(b.memberAdd)
+ b.c.AddHandler(b.memberRemove)
err = b.c.Open()
if err != nil {
return err
diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go
index 8691a612..85bac2ec 100644
--- a/bridge/discord/handlers.go
+++ b/bridge/discord/handlers.go
@@ -123,3 +123,45 @@ func (b *Bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUp
b.nickMemberMap[m.Member.Nick] = m.Member
}
}
+
+func (b *Bdiscord) memberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
+ if m.Member == nil {
+ b.Log.Warnf("Received member update with no member information: %#v", m)
+ return
+ }
+ username := m.Member.User.Username
+ if m.Member.Nick != "" {
+ username = m.Member.Nick
+ }
+
+ rmsg := config.Message{
+ Account: b.Account,
+ Event: config.EventJoinLeave,
+ Username: "system",
+ Text: username + " joins",
+ }
+ b.Log.Debugf("<= Sending message from %s to gateway", b.Account)
+ b.Log.Debugf("<= Message is %#v", rmsg)
+ b.Remote <- rmsg
+}
+
+func (b *Bdiscord) memberRemove(s *discordgo.Session, m *discordgo.GuildMemberRemove) {
+ if m.Member == nil {
+ b.Log.Warnf("Received member update with no member information: %#v", m)
+ return
+ }
+ username := m.Member.User.Username
+ if m.Member.Nick != "" {
+ username = m.Member.Nick
+ }
+
+ rmsg := config.Message{
+ Account: b.Account,
+ Event: config.EventJoinLeave,
+ Username: "system",
+ Text: username + " leaves",
+ }
+ b.Log.Debugf("<= Sending message from %s to gateway", b.Account)
+ b.Log.Debugf("<= Message is %#v", rmsg)
+ b.Remote <- rmsg
+}
diff --git a/gateway/gateway.go b/gateway/gateway.go
index 6ac0abe5..f74a6680 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -174,6 +174,18 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
return channels
}
+ // discord join/leave is for the whole bridge, isn't a per channel join/leave
+ if msg.Event == config.EventJoinLeave && dest.Protocol == "discord" && msg.Account == dest.Account {
+ flog.Error("here")
+ for _, channel := range gw.Channels {
+ if channel.Account == msg.Account && strings.Contains(channel.Direction, "out") &&
+ gw.validGatewayDest(msg) {
+ channels = append(channels, *channel)
+ }
+ }
+ return channels
+ }
+
// if source channel is in only, do nothing
for _, channel := range gw.Channels {
// lookup the channel from the message