From 0bcb0b882f8f49d9ae889165dc4478d1168e1f25 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 17 Feb 2019 21:49:45 +0100 Subject: Support join/leaves from discord. Closes #654 (#721) --- bridge/discord/discord.go | 2 ++ bridge/discord/handlers.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'bridge/discord') 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 +} -- cgit v1.2.3