2016-08-14 12:48:51 -07:00
|
|
|
package birc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2022-02-05 12:12:03 -08:00
|
|
|
"errors"
|
2016-10-29 09:59:12 -07:00
|
|
|
"fmt"
|
2018-05-11 14:02:43 -07:00
|
|
|
"hash/crc32"
|
2020-10-19 15:33:15 -07:00
|
|
|
"io/ioutil"
|
2017-10-20 13:22:13 -07:00
|
|
|
"net"
|
2016-08-14 12:48:51 -07:00
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2018-06-09 03:47:40 -07:00
|
|
|
|
|
|
|
"github.com/42wim/matterbridge/bridge"
|
|
|
|
"github.com/42wim/matterbridge/bridge/config"
|
|
|
|
"github.com/42wim/matterbridge/bridge/helper"
|
|
|
|
"github.com/lrstanley/girc"
|
2020-05-23 12:46:15 -07:00
|
|
|
stripmd "github.com/writeas/go-strip-markdown"
|
2018-11-14 13:43:52 -08:00
|
|
|
|
|
|
|
// We need to import the 'data' package as an implicit dependency.
|
|
|
|
// See: https://godoc.org/github.com/paulrosania/go-charset/charset
|
|
|
|
_ "github.com/paulrosania/go-charset/data"
|
2016-08-14 12:48:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type Birc struct {
|
2018-03-04 14:52:14 -08:00
|
|
|
i *girc.Client
|
|
|
|
Nick string
|
|
|
|
names map[string][]string
|
2018-11-22 15:26:50 -08:00
|
|
|
connected chan error
|
2018-03-04 14:52:14 -08:00
|
|
|
Local chan config.Message // local queue for flood control
|
2018-11-22 15:26:50 -08:00
|
|
|
FirstConnection, authDone bool
|
2018-03-04 14:52:14 -08:00
|
|
|
MessageDelay, MessageQueue, MessageLength int
|
2020-11-22 13:44:15 -08:00
|
|
|
channels map[string]bool
|
2018-03-04 14:52:14 -08:00
|
|
|
|
|
|
|
*bridge.Config
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
|
|
|
|
2018-03-04 14:52:14 -08:00
|
|
|
func New(cfg *bridge.Config) bridge.Bridger {
|
2016-08-14 12:48:51 -07:00
|
|
|
b := &Birc{}
|
2018-03-04 14:52:14 -08:00
|
|
|
b.Config = cfg
|
|
|
|
b.Nick = b.GetString("Nick")
|
2016-08-14 12:48:51 -07:00
|
|
|
b.names = make(map[string][]string)
|
2018-11-22 15:26:50 -08:00
|
|
|
b.connected = make(chan error)
|
2020-11-22 13:44:15 -08:00
|
|
|
b.channels = make(map[string]bool)
|
|
|
|
|
2018-03-04 14:52:14 -08:00
|
|
|
if b.GetInt("MessageDelay") == 0 {
|
|
|
|
b.MessageDelay = 1300
|
2018-03-06 11:51:02 -08:00
|
|
|
} else {
|
|
|
|
b.MessageDelay = b.GetInt("MessageDelay")
|
2016-11-01 14:52:28 -07:00
|
|
|
}
|
2018-03-04 14:52:14 -08:00
|
|
|
if b.GetInt("MessageQueue") == 0 {
|
|
|
|
b.MessageQueue = 30
|
2018-03-06 11:51:02 -08:00
|
|
|
} else {
|
|
|
|
b.MessageQueue = b.GetInt("MessageQueue")
|
2016-11-01 14:52:28 -07:00
|
|
|
}
|
2018-03-04 14:52:14 -08:00
|
|
|
if b.GetInt("MessageLength") == 0 {
|
|
|
|
b.MessageLength = 400
|
2018-03-06 11:51:02 -08:00
|
|
|
} else {
|
|
|
|
b.MessageLength = b.GetInt("MessageLength")
|
2017-05-29 12:54:34 -07:00
|
|
|
}
|
2017-06-17 15:13:10 -07:00
|
|
|
b.FirstConnection = true
|
2016-08-14 12:48:51 -07:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Birc) Command(msg *config.Message) string {
|
2018-11-07 15:46:34 -08:00
|
|
|
if msg.Text == "!users" {
|
2017-10-20 13:22:13 -07:00
|
|
|
b.i.Handlers.Add(girc.RPL_NAMREPLY, b.storeNames)
|
|
|
|
b.i.Handlers.Add(girc.RPL_ENDOFNAMES, b.endNames)
|
2018-11-28 01:58:56 -08:00
|
|
|
b.i.Cmd.SendRaw("NAMES " + msg.Channel) //nolint:errcheck
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-08-15 14:16:07 -07:00
|
|
|
func (b *Birc) Connect() error {
|
2022-02-05 12:12:03 -08:00
|
|
|
if b.GetBool("UseSASL") && b.GetString("TLSClientCertificate") != "" {
|
|
|
|
return errors.New("you can't enable SASL and TLSClientCertificate at the same time")
|
|
|
|
}
|
|
|
|
|
2018-03-06 11:41:34 -08:00
|
|
|
b.Local = make(chan config.Message, b.MessageQueue+10)
|
2018-03-04 14:52:14 -08:00
|
|
|
b.Log.Infof("Connecting %s", b.GetString("Server"))
|
2018-11-28 01:58:56 -08:00
|
|
|
|
|
|
|
i, err := b.getClient()
|
2016-08-15 14:16:07 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-10-20 13:22:13 -07:00
|
|
|
|
2018-03-04 14:52:14 -08:00
|
|
|
if b.GetBool("UseSASL") {
|
2018-11-07 11:36:50 -08:00
|
|
|
i.Config.SASL = &girc.SASLPlain{
|
|
|
|
User: b.GetString("NickServNick"),
|
|
|
|
Pass: b.GetString("NickServPassword"),
|
|
|
|
}
|
2017-10-20 13:22:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
i.Handlers.Add(girc.RPL_WELCOME, b.handleNewConnection)
|
|
|
|
i.Handlers.Add(girc.RPL_ENDOFMOTD, b.handleOtherAuth)
|
2019-01-24 12:58:27 -08:00
|
|
|
i.Handlers.Add(girc.ERR_NOMOTD, b.handleOtherAuth)
|
2018-02-22 09:56:21 -08:00
|
|
|
i.Handlers.Add(girc.ALL_EVENTS, b.handleOther)
|
2019-01-24 12:51:52 -08:00
|
|
|
b.i = i
|
2018-11-22 15:26:50 -08:00
|
|
|
|
2018-11-28 01:58:56 -08:00
|
|
|
go b.doConnect()
|
|
|
|
|
2018-11-22 15:26:50 -08:00
|
|
|
err = <-b.connected
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("connection failed %s", err)
|
2016-10-29 09:59:12 -07:00
|
|
|
}
|
2018-11-22 15:26:50 -08:00
|
|
|
b.Log.Info("Connection succeeded")
|
|
|
|
b.FirstConnection = false
|
2018-03-04 14:52:14 -08:00
|
|
|
if b.GetInt("DebugLevel") == 0 {
|
2018-02-22 09:56:21 -08:00
|
|
|
i.Handlers.Clear(girc.ALL_EVENTS)
|
|
|
|
}
|
2016-11-01 14:52:28 -07:00
|
|
|
go b.doSend()
|
2016-08-15 14:16:07 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-14 12:12:02 -08:00
|
|
|
func (b *Birc) Disconnect() error {
|
2018-03-04 14:52:14 -08:00
|
|
|
b.i.Close()
|
2017-02-14 12:12:02 -08:00
|
|
|
close(b.Local)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-12 05:51:41 -07:00
|
|
|
func (b *Birc) JoinChannel(channel config.ChannelInfo) error {
|
2020-11-22 13:44:15 -08:00
|
|
|
b.channels[channel.Name] = true
|
2018-11-22 15:26:50 -08:00
|
|
|
// need to check if we have nickserv auth done before joining channels
|
|
|
|
for {
|
|
|
|
if b.authDone {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
2017-08-12 05:51:41 -07:00
|
|
|
if channel.Options.Key != "" {
|
2018-02-26 15:33:21 -08:00
|
|
|
b.Log.Debugf("using key %s for channel %s", channel.Options.Key, channel.Name)
|
2017-10-20 13:22:13 -07:00
|
|
|
b.i.Cmd.JoinKey(channel.Name, channel.Options.Key)
|
2017-08-12 05:51:41 -07:00
|
|
|
} else {
|
2017-10-20 13:22:13 -07:00
|
|
|
b.i.Cmd.Join(channel.Name)
|
2017-08-12 05:51:41 -07:00
|
|
|
}
|
2016-09-18 10:21:15 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-27 13:59:37 -07:00
|
|
|
func (b *Birc) Send(msg config.Message) (string, error) {
|
2017-09-11 13:45:15 -07:00
|
|
|
// ignore delete messages
|
2018-11-15 11:43:43 -08:00
|
|
|
if msg.Event == config.EventMsgDelete {
|
2017-09-11 13:45:15 -07:00
|
|
|
return "", nil
|
|
|
|
}
|
2018-02-24 14:56:35 -08:00
|
|
|
|
2018-02-28 13:23:29 -08:00
|
|
|
b.Log.Debugf("=> Receiving %#v", msg)
|
2018-02-24 14:56:35 -08:00
|
|
|
|
2018-03-05 13:50:38 -08:00
|
|
|
// we can be in between reconnects #385
|
|
|
|
if !b.i.IsConnected() {
|
|
|
|
b.Log.Error("Not connected to server, dropping message")
|
2019-04-06 13:34:41 -07:00
|
|
|
return "", nil
|
2018-03-05 13:50:38 -08:00
|
|
|
}
|
|
|
|
|
2018-02-24 14:56:35 -08:00
|
|
|
// Execute a command
|
2016-08-14 12:48:51 -07:00
|
|
|
if strings.HasPrefix(msg.Text, "!") {
|
|
|
|
b.Command(&msg)
|
|
|
|
}
|
2017-08-30 11:59:54 -07:00
|
|
|
|
2018-02-24 14:56:35 -08:00
|
|
|
// convert to specified charset
|
2018-11-28 01:58:56 -08:00
|
|
|
if err := b.handleCharset(&msg); err != nil {
|
|
|
|
return "", err
|
2017-08-30 11:59:54 -07:00
|
|
|
}
|
|
|
|
|
2018-11-28 01:58:56 -08:00
|
|
|
// handle files, return if we're done here
|
|
|
|
if ok := b.handleFiles(&msg); ok {
|
|
|
|
return "", nil
|
2017-11-24 13:36:19 -08:00
|
|
|
}
|
|
|
|
|
2018-11-14 13:43:52 -08:00
|
|
|
var msgLines []string
|
2020-05-23 12:46:15 -07:00
|
|
|
if b.GetBool("StripMarkdown") {
|
|
|
|
msg.Text = stripmd.Strip(msg.Text)
|
|
|
|
}
|
|
|
|
|
2018-03-04 14:52:14 -08:00
|
|
|
if b.GetBool("MessageSplit") {
|
2021-05-27 12:45:23 -07:00
|
|
|
msgLines = helper.GetSubLines(msg.Text, b.MessageLength, b.GetString("MessageClipped"))
|
2018-11-14 13:43:52 -08:00
|
|
|
} else {
|
2021-05-27 12:45:23 -07:00
|
|
|
msgLines = helper.GetSubLines(msg.Text, 0, b.GetString("MessageClipped"))
|
2017-11-24 14:27:13 -08:00
|
|
|
}
|
2018-11-14 13:43:52 -08:00
|
|
|
for i := range msgLines {
|
|
|
|
if len(b.Local) >= b.MessageQueue {
|
2018-02-26 15:33:21 -08:00
|
|
|
b.Log.Debugf("flooding, dropping message (queue at %d)", len(b.Local))
|
2018-11-14 13:43:52 -08:00
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2020-02-09 13:10:18 -08:00
|
|
|
msg.Text = msgLines[i]
|
|
|
|
b.Local <- msg
|
2016-09-29 12:21:24 -07:00
|
|
|
}
|
2017-08-27 13:59:37 -07:00
|
|
|
return "", nil
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
|
|
|
|
2018-11-28 01:58:56 -08:00
|
|
|
func (b *Birc) doConnect() {
|
|
|
|
for {
|
|
|
|
if err := b.i.Connect(); err != nil {
|
|
|
|
b.Log.Errorf("disconnect: error: %s", err)
|
|
|
|
if b.FirstConnection {
|
|
|
|
b.connected <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
b.Log.Info("disconnect: client requested quit")
|
|
|
|
}
|
|
|
|
b.Log.Info("reconnecting in 30 seconds...")
|
|
|
|
time.Sleep(30 * time.Second)
|
|
|
|
b.i.Handlers.Clear(girc.RPL_WELCOME)
|
|
|
|
b.i.Handlers.Add(girc.RPL_WELCOME, func(client *girc.Client, event girc.Event) {
|
|
|
|
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EventRejoinChannels}
|
|
|
|
// set our correct nick on reconnect if necessary
|
|
|
|
b.Nick = event.Source.Name
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-30 09:21:32 -08:00
|
|
|
// Sanitize nicks for RELAYMSG: replace IRC characters with special meanings with "-"
|
|
|
|
func sanitizeNick(nick string) string {
|
|
|
|
sanitize := func(r rune) rune {
|
|
|
|
if strings.ContainsRune("!+%@&#$:'\"?*,. ", r) {
|
|
|
|
return '-'
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
return strings.Map(sanitize, nick)
|
|
|
|
}
|
|
|
|
|
2016-11-01 14:52:28 -07:00
|
|
|
func (b *Birc) doSend() {
|
2018-03-04 14:52:14 -08:00
|
|
|
rate := time.Millisecond * time.Duration(b.MessageDelay)
|
2017-07-13 15:35:01 -07:00
|
|
|
throttle := time.NewTicker(rate)
|
2016-11-01 14:52:28 -07:00
|
|
|
for msg := range b.Local {
|
2017-07-13 15:35:01 -07:00
|
|
|
<-throttle.C
|
2018-05-11 14:02:43 -07:00
|
|
|
username := msg.Username
|
2020-12-30 09:21:32 -08:00
|
|
|
// Optional support for the proposed RELAYMSG extension, described at
|
|
|
|
// https://github.com/jlu5/ircv3-specifications/blob/master/extensions/relaymsg.md
|
|
|
|
// nolint:nestif
|
|
|
|
if (b.i.HasCapability("overdrivenetworks.com/relaymsg") || b.i.HasCapability("draft/relaymsg")) &&
|
|
|
|
b.GetBool("UseRelayMsg") {
|
|
|
|
username = sanitizeNick(username)
|
|
|
|
text := msg.Text
|
|
|
|
|
|
|
|
// Work around girc chomping leading commas on single word messages?
|
|
|
|
if strings.HasPrefix(text, ":") && !strings.ContainsRune(text, ' ') {
|
|
|
|
text = ":" + text
|
|
|
|
}
|
2020-11-22 13:21:02 -08:00
|
|
|
|
2020-12-30 09:21:32 -08:00
|
|
|
if msg.Event == config.EventUserAction {
|
|
|
|
b.i.Cmd.SendRawf("RELAYMSG %s %s :\x01ACTION %s\x01", msg.Channel, username, text) //nolint:errcheck
|
|
|
|
} else {
|
|
|
|
b.Log.Debugf("Sending RELAYMSG to channel %s: nick=%s", msg.Channel, username)
|
|
|
|
b.i.Cmd.SendRawf("RELAYMSG %s %s :%s", msg.Channel, username, text) //nolint:errcheck
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if b.GetBool("Colornicks") {
|
|
|
|
checksum := crc32.ChecksumIEEE([]byte(msg.Username))
|
|
|
|
colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes
|
|
|
|
username = fmt.Sprintf("\x03%02d%s\x0F", colorCode, msg.Username)
|
|
|
|
}
|
|
|
|
switch msg.Event {
|
|
|
|
case config.EventUserAction:
|
|
|
|
b.i.Cmd.Action(msg.Channel, username+msg.Text)
|
|
|
|
case config.EventNoticeIRC:
|
|
|
|
b.Log.Debugf("Sending notice to channel %s", msg.Channel)
|
|
|
|
b.i.Cmd.Notice(msg.Channel, username+msg.Text)
|
|
|
|
default:
|
|
|
|
b.Log.Debugf("Sending to channel %s", msg.Channel)
|
|
|
|
b.i.Cmd.Message(msg.Channel, username+msg.Text)
|
|
|
|
}
|
2017-07-30 08:48:23 -07:00
|
|
|
}
|
2016-11-01 14:52:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 01:58:56 -08:00
|
|
|
// validateInput validates the server/port/nick configuration. Returns a *girc.Client if successful
|
|
|
|
func (b *Birc) getClient() (*girc.Client, error) {
|
|
|
|
server, portstr, err := net.SplitHostPort(b.GetString("Server"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
port, err := strconv.Atoi(portstr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-10-16 14:59:39 -07:00
|
|
|
user := b.GetString("UserName")
|
|
|
|
if user == "" {
|
|
|
|
user = b.GetString("Nick")
|
|
|
|
}
|
2018-11-28 01:58:56 -08:00
|
|
|
// fix strict user handling of girc
|
|
|
|
for !girc.IsValidUser(user) {
|
2019-04-04 15:17:38 -07:00
|
|
|
if len(user) == 1 || len(user) == 0 {
|
2018-11-28 01:58:56 -08:00
|
|
|
user = "matterbridge"
|
|
|
|
break
|
|
|
|
}
|
|
|
|
user = user[1:]
|
|
|
|
}
|
2021-10-16 14:59:39 -07:00
|
|
|
realName := b.GetString("RealName")
|
|
|
|
if realName == "" {
|
|
|
|
realName = b.GetString("Nick")
|
|
|
|
}
|
2018-11-28 01:58:56 -08:00
|
|
|
|
2020-10-19 15:33:15 -07:00
|
|
|
debug := ioutil.Discard
|
|
|
|
if b.GetInt("DebugLevel") == 2 {
|
|
|
|
debug = b.Log.Writer()
|
|
|
|
}
|
|
|
|
|
2020-10-20 16:14:13 -07:00
|
|
|
pingDelay, err := time.ParseDuration(b.GetString("pingdelay"))
|
|
|
|
if err != nil || pingDelay == 0 {
|
|
|
|
pingDelay = time.Minute
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Log.Debugf("setting pingdelay to %s", pingDelay)
|
|
|
|
|
2022-02-05 12:12:03 -08:00
|
|
|
tlsConfig, err := b.getTLSConfig()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-11-28 01:58:56 -08:00
|
|
|
i := girc.New(girc.Config{
|
|
|
|
Server: server,
|
|
|
|
ServerPass: b.GetString("Password"),
|
|
|
|
Port: port,
|
|
|
|
Nick: b.GetString("Nick"),
|
|
|
|
User: user,
|
2021-10-16 14:59:39 -07:00
|
|
|
Name: realName,
|
2018-11-28 01:58:56 -08:00
|
|
|
SSL: b.GetBool("UseTLS"),
|
2021-11-28 16:15:51 -08:00
|
|
|
Bind: b.GetString("Bind"),
|
2022-02-05 12:12:03 -08:00
|
|
|
TLSConfig: tlsConfig,
|
2020-10-20 16:14:13 -07:00
|
|
|
PingDelay: pingDelay,
|
2020-06-24 14:57:37 -07:00
|
|
|
// skip gIRC internal rate limiting, since we have our own throttling
|
2020-12-30 09:21:32 -08:00
|
|
|
AllowFlood: true,
|
|
|
|
Debug: debug,
|
|
|
|
SupportedCaps: map[string][]string{"overdrivenetworks.com/relaymsg": nil, "draft/relaymsg": nil},
|
2018-11-28 01:58:56 -08:00
|
|
|
})
|
|
|
|
return i, nil
|
|
|
|
}
|
|
|
|
|
2017-10-20 13:22:13 -07:00
|
|
|
func (b *Birc) endNames(client *girc.Client, event girc.Event) {
|
|
|
|
channel := event.Params[1]
|
2016-08-14 12:48:51 -07:00
|
|
|
sort.Strings(b.names[channel])
|
|
|
|
maxNamesPerPost := (300 / b.nicksPerRow()) * b.nicksPerRow()
|
|
|
|
for len(b.names[channel]) > maxNamesPerPost {
|
2021-05-27 12:45:23 -07:00
|
|
|
b.Remote <- config.Message{
|
|
|
|
Username: b.Nick, Text: b.formatnicks(b.names[channel][0:maxNamesPerPost]),
|
|
|
|
Channel: channel, Account: b.Account,
|
|
|
|
}
|
2016-08-14 12:48:51 -07:00
|
|
|
b.names[channel] = b.names[channel][maxNamesPerPost:]
|
|
|
|
}
|
2021-05-27 12:45:23 -07:00
|
|
|
b.Remote <- config.Message{
|
|
|
|
Username: b.Nick, Text: b.formatnicks(b.names[channel]),
|
|
|
|
Channel: channel, Account: b.Account,
|
|
|
|
}
|
2016-08-14 12:48:51 -07:00
|
|
|
b.names[channel] = nil
|
2017-10-20 13:22:13 -07:00
|
|
|
b.i.Handlers.Clear(girc.RPL_NAMREPLY)
|
|
|
|
b.i.Handlers.Clear(girc.RPL_ENDOFNAMES)
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
|
|
|
|
2018-02-24 14:56:35 -08:00
|
|
|
func (b *Birc) skipPrivMsg(event girc.Event) bool {
|
|
|
|
// Our nick can be changed
|
2017-06-17 15:13:10 -07:00
|
|
|
b.Nick = b.i.GetNick()
|
2018-02-24 14:56:35 -08:00
|
|
|
|
2017-06-17 15:13:10 -07:00
|
|
|
// freenode doesn't send 001 as first reply
|
2020-11-22 13:21:02 -08:00
|
|
|
if event.Command == "NOTICE" && len(event.Params) != 2 {
|
2018-02-24 14:56:35 -08:00
|
|
|
return true
|
2017-06-17 15:13:10 -07:00
|
|
|
}
|
2016-10-29 07:27:07 -07:00
|
|
|
// don't forward queries to the bot
|
2017-10-20 13:22:13 -07:00
|
|
|
if event.Params[0] == b.Nick {
|
2018-02-24 14:56:35 -08:00
|
|
|
return true
|
2016-10-29 07:27:07 -07:00
|
|
|
}
|
2016-10-29 07:35:16 -07:00
|
|
|
// don't forward message from ourself
|
2022-03-12 08:33:39 -08:00
|
|
|
if event.Source != nil {
|
|
|
|
if event.Source.Name == b.Nick {
|
|
|
|
return true
|
|
|
|
}
|
2018-02-24 14:56:35 -08:00
|
|
|
}
|
2020-12-30 09:21:32 -08:00
|
|
|
// don't forward messages we sent via RELAYMSG
|
|
|
|
if relayedNick, ok := event.Tags.Get("draft/relaymsg"); ok && relayedNick == b.Nick {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
// This is the old name of the cap sent in spoofed messages; I've kept this in
|
|
|
|
// for compatibility reasons
|
|
|
|
if relayedNick, ok := event.Tags.Get("relaymsg"); ok && relayedNick == b.Nick {
|
|
|
|
return true
|
|
|
|
}
|
2018-02-24 14:56:35 -08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-08-14 12:48:51 -07:00
|
|
|
func (b *Birc) nicksPerRow() int {
|
2016-09-18 10:21:15 -07:00
|
|
|
return 4
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
|
|
|
|
2017-10-20 13:22:13 -07:00
|
|
|
func (b *Birc) storeNames(client *girc.Client, event girc.Event) {
|
|
|
|
channel := event.Params[2]
|
2016-08-14 12:48:51 -07:00
|
|
|
b.names[channel] = append(
|
|
|
|
b.names[channel],
|
2019-02-16 08:24:04 -08:00
|
|
|
strings.Split(strings.TrimSpace(event.Last()), " ")...)
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
|
|
|
|
2018-11-07 15:29:30 -08:00
|
|
|
func (b *Birc) formatnicks(nicks []string) string {
|
2018-11-14 13:43:52 -08:00
|
|
|
return strings.Join(nicks, ", ") + " currently on IRC"
|
2016-08-14 12:48:51 -07:00
|
|
|
}
|
2022-02-05 12:12:03 -08:00
|
|
|
|
|
|
|
func (b *Birc) getTLSConfig() (*tls.Config, error) {
|
|
|
|
server, _, _ := net.SplitHostPort(b.GetString("server"))
|
|
|
|
|
|
|
|
tlsConfig := &tls.Config{
|
|
|
|
InsecureSkipVerify: b.GetBool("skiptlsverify"), //nolint:gosec
|
|
|
|
ServerName: server,
|
|
|
|
}
|
|
|
|
|
|
|
|
if filename := b.GetString("TLSClientCertificate"); filename != "" {
|
|
|
|
cert, err := tls.LoadX509KeyPair(filename, filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsConfig.Certificates = []tls.Certificate{cert}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tlsConfig, nil
|
|
|
|
}
|