~arsen/irc-discord-bridgebot

139101715465cb699f04e796d3b641f1b935912d — Arsen Arsenović 2 years ago 559557f
irc: set realname according to usernames
1 files changed, 16 insertions(+), 0 deletions(-)

M pkg/sides/irc/irc.go
M pkg/sides/irc/irc.go => pkg/sides/irc/irc.go +16 -0
@@ 67,6 67,9 @@ type IRCConnection struct {
	desiredNick  string
	retryCounter int

	realnameMutex sync.Mutex
	realname      string

	runDesireable uint32
	runCondition  *sync.Cond
}


@@ 155,6 158,10 @@ func (conn *IRCConnection) run() {
		var readynessGroup sync.WaitGroup
		readynessGroup.Add(1)

		conn.realnameMutex.Lock()
		realname := conn.realname
		conn.realnameMutex.Unlock()

		ircConn := girc.New(girc.Config{
			Server: conn.parentSide.host,
			Port:   int(conn.parentSide.port),


@@ 162,6 169,7 @@ func (conn *IRCConnection) run() {

			Nick:  nickGen(),
			User:  "IDB", // hopefully set via identd properly
			Name:  realname,
			Debug: os.Stderr,

			HandleNickCollide: func(n string) string {


@@ 393,6 401,10 @@ func (is *IRCSide) AddEntity(e sides.Entity, c string) {

	conn := is.getConnection(e)

	conn.realnameMutex.Lock()
	conn.realname = e.Username
	conn.realnameMutex.Unlock()

	atomic.StoreUint32(&conn.runDesireable, 1)
	conn.runCondition.Broadcast()
}


@@ 426,6 438,10 @@ func (is *IRCSide) ChangeEntity(sender sides.Entity) {
		return
	}

	conn.realnameMutex.Lock()
	conn.realname = sender.Username
	conn.realnameMutex.Unlock()

	nick := sender.Nick
	if nick == "" {
		nick = sender.Username