From 0e434f1c2d2c74b96730b807d2b6409a026ff493 Mon Sep 17 00:00:00 2001 From: blackbeard420 Date: Sat, 23 Jan 2021 22:02:23 -0500 Subject: [PATCH] SendRaw SendPong uses SendRaw before the rest will be implemented to use it Kill New function to terminate event loop --- irc.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/irc.go b/irc.go index f2920bc..9380405 100644 --- a/irc.go +++ b/irc.go @@ -43,11 +43,16 @@ func cleanInput(msg string) string { return ret } +//SendRaw sends a string as a raw irc message +func (c *Connection) SendRaw(msg string) error { + _, err := c.Sock.Write([]byte(msg)) + return err +} + //SendPong replies to the received PING func (c *Connection) SendPong(ping string) { pong := strings.Replace(ping, "PING", "PONG", 1) - c.Sock.Write([]byte(fmt.Sprintf("%s\n", pong))) - log.Println("pong sent") + c.SendRaw(pong + "\n") } //SendPrivmsg sends a privmsg to channel/target @@ -114,6 +119,11 @@ func (c *Connection) GetNicks(channel string) []string { return c.userList[channel] } +//Kill terminates the event loop of connection +func (c *Connection) Kill() { + c.Sock.Close() +} + //NewConnection creates and connects an Connection func NewConnection(server, nick, user string, pass *string, chans []string) *Connection { irc := &Connection{channels: chans, userList: map[string][]string{}}