mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 12:50:27 +00:00
Add UserID to each message. Closes #200
This commit is contained in:
parent
2dd402675d
commit
2ddc4f7ae9
@ -21,6 +21,7 @@ type Api struct {
|
|||||||
type ApiMessage struct {
|
type ApiMessage struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
UserID string `json:"userid"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Gateway string `json:"gateway"`
|
Gateway string `json:"gateway"`
|
||||||
}
|
}
|
||||||
@ -81,6 +82,7 @@ func (b *Api) handlePostMessage(c echo.Context) error {
|
|||||||
b.Remote <- config.Message{
|
b.Remote <- config.Message{
|
||||||
Text: message.Text,
|
Text: message.Text,
|
||||||
Username: message.Username,
|
Username: message.Username,
|
||||||
|
UserID: message.UserID,
|
||||||
Channel: "api",
|
Channel: "api",
|
||||||
Avatar: message.Avatar,
|
Avatar: message.Avatar,
|
||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
|
@ -19,6 +19,7 @@ type Message struct {
|
|||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
UserID string `json:"userid"` // userid on the bridge
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Account string `json:"account"`
|
Account string `json:"account"`
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
|
@ -142,7 +142,8 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
|||||||
m.Message.Content = b.stripCustomoji(m.Message.Content)
|
m.Message.Content = b.stripCustomoji(m.Message.Content)
|
||||||
m.Message.Content = b.replaceChannelMentions(m.Message.Content)
|
m.Message.Content = b.replaceChannelMentions(m.Message.Content)
|
||||||
b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,
|
b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,
|
||||||
Account: b.Account, 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",
|
||||||
|
UserID: m.Author.ID}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {
|
func (b *bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {
|
||||||
|
@ -82,7 +82,7 @@ func (b *Bgitter) JoinChannel(channel string) error {
|
|||||||
if !strings.HasSuffix(ev.Message.Text, "") {
|
if !strings.HasSuffix(ev.Message.Text, "") {
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
|
||||||
b.Remote <- config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room,
|
b.Remote <- config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room,
|
||||||
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username)}
|
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID}
|
||||||
}
|
}
|
||||||
case *gitter.GitterConnectionClosed:
|
case *gitter.GitterConnectionClosed:
|
||||||
flog.Errorf("connection with gitter closed for room %s", room)
|
flog.Errorf("connection with gitter closed for room %s", room)
|
||||||
|
@ -252,7 +252,7 @@ func (b *Birc) handlePrivMsg(event *irc.Event) {
|
|||||||
re := regexp.MustCompile(`[[:cntrl:]](\d+,|)\d+`)
|
re := regexp.MustCompile(`[[:cntrl:]](\d+,|)\d+`)
|
||||||
msg = re.ReplaceAllString(msg, "")
|
msg = re.ReplaceAllString(msg, "")
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", event.Arguments[0], b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", event.Arguments[0], b.Account)
|
||||||
b.Remote <- config.Message{Username: event.Nick, Text: msg, Channel: event.Arguments[0], Account: b.Account}
|
b.Remote <- config.Message{Username: event.Nick, Text: msg, Channel: event.Arguments[0], Account: b.Account, UserID: event.User + "@" + event.Host}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birc) handleTopicWhoTime(event *irc.Event) {
|
func (b *Birc) handleTopicWhoTime(event *irc.Event) {
|
||||||
|
@ -109,7 +109,7 @@ func (b *Bmatrix) handlematrix() error {
|
|||||||
username = re.ReplaceAllString(username, `$1`)
|
username = re.ReplaceAllString(username, `$1`)
|
||||||
}
|
}
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account)
|
||||||
b.Remote <- config.Message{Username: username, Text: ev.Content["body"].(string), Channel: channel, Account: b.Account}
|
b.Remote <- config.Message{Username: username, Text: ev.Content["body"].(string), Channel: channel, Account: b.Account, UserID: ev.Sender}
|
||||||
}
|
}
|
||||||
flog.Debugf("Received: %#v", ev)
|
flog.Debugf("Received: %#v", ev)
|
||||||
})
|
})
|
||||||
|
@ -21,6 +21,7 @@ type MMMessage struct {
|
|||||||
Text string
|
Text string
|
||||||
Channel string
|
Channel string
|
||||||
Username string
|
Username string
|
||||||
|
UserID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bmattermost struct {
|
type Bmattermost struct {
|
||||||
@ -127,7 +128,7 @@ func (b *Bmattermost) handleMatter() {
|
|||||||
}
|
}
|
||||||
for message := range mchan {
|
for message := range mchan {
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
|
||||||
b.Remote <- config.Message{Text: message.Text, Username: message.Username, Channel: message.Channel, Account: b.Account}
|
b.Remote <- config.Message{Text: message.Text, Username: message.Username, Channel: message.Channel, Account: b.Account, UserID: message.UserID}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +151,7 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) {
|
|||||||
b.mc.User.Username != message.Username && message.Raw.Data["team_id"].(string) == b.TeamId {
|
b.mc.User.Username != message.Username && message.Raw.Data["team_id"].(string) == b.TeamId {
|
||||||
flog.Debugf("Receiving from matterclient %#v", message)
|
flog.Debugf("Receiving from matterclient %#v", message)
|
||||||
m := &MMMessage{}
|
m := &MMMessage{}
|
||||||
|
m.UserID = message.UserID
|
||||||
m.Username = message.Username
|
m.Username = message.Username
|
||||||
m.Channel = message.Channel
|
m.Channel = message.Channel
|
||||||
m.Text = message.Text
|
m.Text = message.Text
|
||||||
@ -171,6 +173,7 @@ func (b *Bmattermost) handleMatterHook(mchan chan *MMMessage) {
|
|||||||
message := b.mh.Receive()
|
message := b.mh.Receive()
|
||||||
flog.Debugf("Receiving from matterhook %#v", message)
|
flog.Debugf("Receiving from matterhook %#v", message)
|
||||||
m := &MMMessage{}
|
m := &MMMessage{}
|
||||||
|
m.UserID = message.UserID
|
||||||
m.Username = message.UserName
|
m.Username = message.UserName
|
||||||
m.Text = message.Text
|
m.Text = message.Text
|
||||||
m.Channel = message.ChannelName
|
m.Channel = message.ChannelName
|
||||||
|
@ -82,6 +82,6 @@ func (b *Brocketchat) handleRocketHook() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", message.UserName, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", message.UserName, b.Account)
|
||||||
b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account}
|
b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account, UserID: message.UserID}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ type MMMessage struct {
|
|||||||
Text string
|
Text string
|
||||||
Channel string
|
Channel string
|
||||||
Username string
|
Username string
|
||||||
|
UserID string
|
||||||
Raw *slack.MessageEvent
|
Raw *slack.MessageEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +186,7 @@ func (b *Bslack) handleSlack() {
|
|||||||
texts := strings.Split(message.Text, "\n")
|
texts := strings.Split(message.Text, "\n")
|
||||||
for _, text := range texts {
|
for _, text := range texts {
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
|
||||||
b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username)}
|
b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username), UserID: message.UserID}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,6 +214,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
m := &MMMessage{}
|
m := &MMMessage{}
|
||||||
|
m.UserID = user.ID
|
||||||
m.Username = user.Name
|
m.Username = user.Name
|
||||||
m.Channel = channel.Name
|
m.Channel = channel.Name
|
||||||
m.Text = ev.Text
|
m.Text = ev.Text
|
||||||
|
@ -132,7 +132,7 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
|||||||
}
|
}
|
||||||
if text != "" {
|
if text != "" {
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", username, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", username, b.Account)
|
||||||
b.Remote <- config.Message{Username: username, Text: text, Channel: channel, Account: b.Account}
|
b.Remote <- config.Message{Username: username, Text: text, Channel: channel, Account: b.Account, UserID: strconv.Itoa(message.From.ID)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func (b *Bxmpp) handleXmpp() error {
|
|||||||
}
|
}
|
||||||
if nick != b.Config.Nick && v.Stamp == nodelay && v.Text != "" {
|
if nick != b.Config.Nick && v.Stamp == nodelay && v.Text != "" {
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", nick, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", nick, b.Account)
|
||||||
b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Account: b.Account}
|
b.Remote <- config.Message{Username: nick, Text: v.Text, Channel: channel, Account: b.Account, UserID: v.Remote}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case xmpp.Presence:
|
case xmpp.Presence:
|
||||||
|
@ -198,9 +198,6 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) {
|
|||||||
log.Debug("empty channel")
|
log.Debug("empty channel")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// hide message from bridge
|
|
||||||
//if msg.Text HideMessagesPrefix
|
|
||||||
|
|
||||||
originchannel := msg.Channel
|
originchannel := msg.Channel
|
||||||
origmsg := msg
|
origmsg := msg
|
||||||
for _, channel := range gw.DestChannelFunc(&msg, *dest) {
|
for _, channel := range gw.DestChannelFunc(&msg, *dest) {
|
||||||
|
@ -37,6 +37,7 @@ type Message struct {
|
|||||||
Username string
|
Username string
|
||||||
Text string
|
Text string
|
||||||
Type string
|
Type string
|
||||||
|
UserID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Team struct {
|
type Team struct {
|
||||||
@ -290,6 +291,7 @@ func (m *MMClient) parseActionPost(rmsg *Message) {
|
|||||||
}
|
}
|
||||||
rmsg.Username = m.GetUserName(data.UserId)
|
rmsg.Username = m.GetUserName(data.UserId)
|
||||||
rmsg.Channel = m.GetChannelName(data.ChannelId)
|
rmsg.Channel = m.GetChannelName(data.ChannelId)
|
||||||
|
rmsg.UserID = data.UserId
|
||||||
rmsg.Type = data.Type
|
rmsg.Type = data.Type
|
||||||
teamid, _ := rmsg.Raw.Data["team_id"].(string)
|
teamid, _ := rmsg.Raw.Data["team_id"].(string)
|
||||||
// edit messsages have no team_id for some reason
|
// edit messsages have no team_id for some reason
|
||||||
|
Loading…
Reference in New Issue
Block a user