diff options
author | Fredrik de Vibe <fdv@ifi.uio.no> | 2016-03-18 15:12:58 -0400 |
---|---|---|
committer | Fredrik de Vibe <fdv@ifi.uio.no> | 2016-03-18 15:19:13 -0400 |
commit | e0379ca5af0658f59dbee78b730ebd87c279886d (patch) | |
tree | 0c20aadccfd23d8bc6b6ffe5b10df1ddd7396075 | |
parent | 4759ee6132e1a8ec1274870b5cf20ae36d02996c (diff) | |
download | matterbridge-msglm-e0379ca5af0658f59dbee78b730ebd87c279886d.tar.gz matterbridge-msglm-e0379ca5af0658f59dbee78b730ebd87c279886d.tar.bz2 matterbridge-msglm-e0379ca5af0658f59dbee78b730ebd87c279886d.zip |
Enable !users command and add a table formatter
* Listen to wildcarded events, currently handle RPL_NAMREPLY.
* Add a formatter to present nick lists from IRC as a table.
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | config.go | 2 | ||||
-rw-r--r-- | matterbridge.conf.sample | 2 | ||||
-rw-r--r-- | matterbridge.go | 49 |
4 files changed, 55 insertions, 2 deletions
@@ -58,6 +58,10 @@ channel="#matterbridge" UseSlackCircumfix=false #whether to prefix messages from IRC to mattermost with the sender's nick. Useful if username overrides for incoming webhooks isn't enabled on the mattermost server PrefixMessagesWithNick=false +#how to format the list of IRC nicks when displayed in mattermost. Possible options are "table" and "plain" +NickFormatter=plain +#how many nicks to list per row for formatters that support this +NicksPerRow=4 [mattermost] #url is your incoming webhook url (account settings - integrations - incoming webhooks) @@ -17,6 +17,8 @@ type Config struct { Channel string UseSlackCircumfix bool PrefixMessagesWithNick bool + NicksPerRow int + NickFormatter string } Mattermost struct { URL string diff --git a/matterbridge.conf.sample b/matterbridge.conf.sample index 843402e0..4caf6c86 100644 --- a/matterbridge.conf.sample +++ b/matterbridge.conf.sample @@ -7,6 +7,8 @@ nick="matterbot" channel="#matterbridge" UseSlackCircumfix=false PrefixMessagesWithNick=false +NickFormatter=plain +NicksPerRow=4 [mattermost] url="http://yourdomain/hooks/yourhookkey" diff --git a/matterbridge.go b/matterbridge.go index 4302cf17..d2b996a4 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -58,7 +58,7 @@ func (b *Bridge) createIRC(name string) *irc.Connection { i.AddCallback("JOIN", b.handleJoinPart) i.AddCallback("PART", b.handleJoinPart) } - //i.AddCallback("353", b.handleOther) + i.AddCallback("*", b.handleOther) return i } @@ -76,11 +76,54 @@ func (b *Bridge) handleJoinPart(event *irc.Event) { //b.SendType(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]), "join_leave") } +func tableformatter (nicks_s string, nicksPerRow int) string { + nicks := strings.Split(nicks_s, " ") + result := "|IRC users" + if nicksPerRow < 1 { + nicksPerRow = 4 + } + for i := 0; i < 2; i++ { + for j := 1; j <= nicksPerRow; j++ { + if i == 0 { + result += "|" + } else { + result += ":-|" + } + } + result += "\r\n|" + } + result += nicks[0] + "|" + for i := 1; i < len(nicks); i++ { + if i % nicksPerRow == 0 { + result += "\r\n|" + nicks[i] + "|" + } else { + result += nicks[i] + "|" + } + } + return result +} + +func plainformatter (nicks string, nicksPerRow int) string { + return nicks + " currently on IRC" +} + +func (b *Bridge) formatnicks (nicks string) string { + switch (b.Config.IRC.NickFormatter) { + case "table": + return tableformatter(nicks, b.Config.IRC.NicksPerRow) + default: + return plainformatter(nicks, b.Config.IRC.NicksPerRow) + } +} + func (b *Bridge) handleOther(event *irc.Event) { switch event.Code { case "353": log.Println("handleOther", b.getMMChannel(event.Arguments[0])) - b.Send(b.Config.IRC.Nick, event.Message()+" currently on IRC", b.getMMChannel(event.Arguments[0])) + b.Send(b.Config.IRC.Nick, b.formatnicks(event.Message()), b.getMMChannel(event.Arguments[0])) + break + default: + log.Printf("got unknown event: %+v\n", event); } } @@ -119,9 +162,11 @@ func (b *Bridge) handleMatter() { case "!users": log.Println("received !users from", message.UserName) b.i.SendRaw("NAMES " + b.getIRCChannel(message.Token)) + return case "!gif": message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1))) b.Send(b.Config.IRC.Nick, message.Text, b.getIRCChannel(message.Token)) + return } texts := strings.Split(message.Text, "\n") for _, text := range texts { |