4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 23:29:25 +00:00
This commit is contained in:
Wim
2016-11-13 23:06:37 +01:00
parent 14830d9f1c
commit 99d130d1ed
10 changed files with 141 additions and 247 deletions

View File

@ -11,8 +11,7 @@ type bdiscord struct {
c *discordgo.Session
Config *config.Protocol
Remote chan config.Message
protocol string
origin string
Account string
Channels []*discordgo.Channel
Nick string
UseChannelID bool
@ -25,12 +24,11 @@ func init() {
flog = log.WithFields(log.Fields{"module": protocol})
}
func New(cfg config.Protocol, origin string, c chan config.Message) *bdiscord {
func New(cfg config.Protocol, account string, c chan config.Message) *bdiscord {
b := &bdiscord{}
b.Config = &cfg
b.Remote = c
b.protocol = protocol
b.origin = origin
b.Account = account
return b
}
@ -72,10 +70,6 @@ func (b *bdiscord) Connect() error {
return nil
}
func (b *bdiscord) FullOrigin() string {
return b.protocol + "." + b.origin
}
func (b *bdiscord) JoinChannel(channel string) error {
idcheck := strings.Split(channel, "ID:")
if len(idcheck) > 1 {
@ -84,18 +78,6 @@ func (b *bdiscord) JoinChannel(channel string) error {
return nil
}
func (b *bdiscord) Name() string {
return b.protocol + "." + b.origin
}
func (b *bdiscord) Protocol() string {
return b.protocol
}
func (b *bdiscord) Origin() string {
return b.origin
}
func (b *bdiscord) Send(msg config.Message) error {
flog.Debugf("Receiving %#v", msg)
channelID := b.getChannelID(msg.Channel)
@ -103,8 +85,7 @@ func (b *bdiscord) Send(msg config.Message) error {
flog.Errorf("Could not find channelID for %v", msg.Channel)
return nil
}
nick := config.GetNick(&msg, b.Config)
b.c.ChannelMessageSend(channelID, nick+msg.Text)
b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
return nil
}
@ -121,13 +102,13 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
if m.Content == "" {
return
}
flog.Debugf("Sending message from %s on %s to gateway", m.Author.Username, b.FullOrigin())
flog.Debugf("Sending message from %s on %s to gateway", m.Author.Username, b.Account)
channelName := b.getChannelName(m.ChannelID)
if b.UseChannelID {
channelName = "ID:" + m.ChannelID
}
b.Remote <- config.Message{Username: m.Author.Username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,
Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin(), Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}
Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}
}
func (b *bdiscord) getChannelID(name string) string {