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:
kayos@tcp.direct 2021-10-07 11:46:24 -07:00
parent 8c7d67ec38
commit 2825aaba2b
4 changed files with 12 additions and 2 deletions

View File

@ -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:

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -191,7 +191,6 @@ func main() {
if err != nil {
// log.WithField("error", err).Fatalln("Go-Discord-IRC failed to start.")
panic(err)
return
}
}()
// Inform the user that things are happening!