mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-24 20:11:36 +00:00
parent
4525fa31aa
commit
0bcb0b882f
@ -75,6 +75,8 @@ func (b *Bdiscord) Connect() error {
|
|||||||
b.c.AddHandler(b.memberUpdate)
|
b.c.AddHandler(b.memberUpdate)
|
||||||
b.c.AddHandler(b.messageUpdate)
|
b.c.AddHandler(b.messageUpdate)
|
||||||
b.c.AddHandler(b.messageDelete)
|
b.c.AddHandler(b.messageDelete)
|
||||||
|
b.c.AddHandler(b.memberAdd)
|
||||||
|
b.c.AddHandler(b.memberRemove)
|
||||||
err = b.c.Open()
|
err = b.c.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -123,3 +123,45 @@ func (b *Bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUp
|
|||||||
b.nickMemberMap[m.Member.Nick] = m.Member
|
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
|
||||||
|
}
|
||||||
|
@ -174,6 +174,18 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
|
|||||||
return channels
|
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
|
// if source channel is in only, do nothing
|
||||||
for _, channel := range gw.Channels {
|
for _, channel := range gw.Channels {
|
||||||
// lookup the channel from the message
|
// lookup the channel from the message
|
||||||
|
Loading…
Reference in New Issue
Block a user