Browse Source

client: Added Say(f), Describe(f) to send cut messages to channels and nicks.

master
Gisle Aune 6 years ago
parent
commit
b4c7c5145f
  1. 30
      client.go
  2. 4
      event.go

30
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...)) 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 // 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 // unless the internal channel is filled up. The returned context can be used to
// wait for the event, or the client's destruction. // wait for the event, or the client's destruction.

4
event.go

@ -109,8 +109,8 @@ func (event *Event) Hidden() bool {
return event.hidden 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 { func (event *Event) Arg(index int) string {
if index < 0 || index > len(event.Args) { if index < 0 || index > len(event.Args) {
return "" return ""

Loading…
Cancel
Save