fix listener bot not using keys from configs, add mutex for discord messages in an attempt to fix out of order messages
This commit is contained in:
parent
8c7d67ec38
commit
2825aaba2b
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
irc "git.tcp.direct/kayos/girc-tcpd"
|
||||
|
@ -341,6 +342,7 @@ func (b *Bridge) GetMappingByDiscord(channel string) (Mapping, bool) {
|
|||
var emojiRegex = regexp.MustCompile("(:[a-zA-Z_-]+:)")
|
||||
|
||||
func (b *Bridge) loop() {
|
||||
var discordmu = &sync.Mutex{}
|
||||
for {
|
||||
select {
|
||||
|
||||
|
@ -370,6 +372,7 @@ func (b *Bridge) loop() {
|
|||
username += `.` // <- zero width space in here, ayylmao
|
||||
}
|
||||
}
|
||||
discordmu.Lock()
|
||||
|
||||
content := msg.Message
|
||||
|
||||
|
@ -428,6 +431,7 @@ func (b *Bridge) loop() {
|
|||
}
|
||||
}()
|
||||
}
|
||||
discordmu.Unlock()
|
||||
|
||||
// Messages from Discord to IRC
|
||||
case msg := <-b.discordMessageEventsChan:
|
||||
|
|
|
@ -198,7 +198,12 @@ func (i *ircListener) SetDebugMode(debug bool) {
|
|||
|
||||
func (i *ircListener) JoinChannels(c *irc.Client, e irc.Event) {
|
||||
for _, mapping := range i.bridge.mappings {
|
||||
c.Cmd.Join(mapping.IRCChannel)
|
||||
key, keyed := i.bridge.ircChannelKeys[mapping.IRCChannel]
|
||||
if !keyed {
|
||||
c.Cmd.Join(mapping.IRCChannel)
|
||||
} else {
|
||||
c.Cmd.JoinKey(mapping.IRCChannel, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
package dstate
|
||||
|
||||
import "github.com/matterbridge/discordgo"
|
||||
import "time"
|
||||
|
||||
func ChannelMessage(s *discordgo.Session, channelID string, messageID string) (*discordgo.Message, error) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if msg, err := s.State.Message(channelID, messageID); err == nil {
|
||||
return msg, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue