From b4c7c5145f2e2c430d6a74035751e6d59df7ec32 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sat, 24 Nov 2018 10:04:07 +0100 Subject: [PATCH] client: Added Say(f), Describe(f) to send cut messages to channels and nicks. --- client.go | 30 ++++++++++++++++++++++++++++++ event.go | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 708b0e3..86cd8f6 100644 --- a/client.go +++ b/client.go @@ -309,6 +309,36 @@ func (client *Client) SendCTCPf(verb, targetName string, reply bool, format stri client.SendCTCP(verb, targetName, reply, fmt.Sprintf(format, a...)) } +// Say sends a PRIVMSG with the target name and text, cutting the message if it gets too long. +func (client *Client) Say(targetName string, text string) { + overhead := client.PrivmsgOverhead(targetName, false) + cuts := ircutil.CutMessage(text, overhead) + + for _, cut := range cuts { + client.SendQueuedf("PRIVMSG %s :%s", targetName, cut) + } +} + +// Sayf is Say with a fmt.Sprintf. +func (client *Client) Sayf(targetName string, format string, a ...interface{}) { + client.Say(targetName, fmt.Sprintf(format, a...)) +} + +// Describe sends a CTCP ACTION with the target name and text, cutting the message if it gets too long. +func (client *Client) Describe(targetName string, text string) { + overhead := client.PrivmsgOverhead(targetName, true) + cuts := ircutil.CutMessage(text, overhead) + + for _, cut := range cuts { + client.SendQueuedf("PRIVMSG %s :\x01ACTION %s\x01", targetName, cut) + } +} + +// Describef is Describe with a fmt.Sprintf. +func (client *Client) Describef(targetName string, format string, a ...interface{}) { + client.Describe(targetName, fmt.Sprintf(format, a...)) +} + // Emit sends an event through the client's event, and it will return immediately // unless the internal channel is filled up. The returned context can be used to // wait for the event, or the client's destruction. diff --git a/event.go b/event.go index 8dec817..e8c9e04 100644 --- a/event.go +++ b/event.go @@ -109,8 +109,8 @@ func (event *Event) Hidden() bool { return event.hidden } -// Arg gets the argument by index. The rationale behind it is that some -// servers may use it for the last argument in JOINs and such. +// Arg gets the argument by index, counting the trailing as the last argument. The rationale +// behind it is that some servers may use it for the last argument in JOINs and such. func (event *Event) Arg(index int) string { if index < 0 || index > len(event.Args) { return ""