https://github.com/gianarb/go-irc
Go IRC low level library
https://github.com/gianarb/go-irc
Last synced: about 1 year ago
JSON representation
Go IRC low level library
- Host: GitHub
- URL: https://github.com/gianarb/go-irc
- Owner: gianarb
- Created: 2014-08-23T12:20:49.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2020-11-13T15:09:20.000Z (over 5 years ago)
- Last Synced: 2024-11-01T08:42:23.982Z (over 1 year ago)
- Language: Go
- Homepage: http://gianarb.it/blog/chatops-create-your-own-irc-bot-in-go
- Size: 8.79 KB
- Stars: 21
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## go-irc
Library to interact with IRC.
### PACKAGE DOCUMENTATION
```go
package irc
```
```go
type Bot struct {
// contains filtered or unexported fields
}
```
Implement BotInterface
```go
type BotInterface interface {
Connect(conn net.Conn, err error)
Send(string)
}
```
Bot struct contains : host, nickname, user, channel ...
```go
func NewBot(proxy string, server string, nick string, user string, channel string, pass string) *Bot
```
Returns new Bot
Bot Methods
* ``` func (bot *Bot) Connect() (conn net.Conn, err error)``` : Connect bot to irc server
* ``` func (bot *Bot) Send(command string) ``` : Send message to channel after connection
```
type Message struct {
Draft string
}
```
Best practice for managing simple update of lib
### Use Case
```go
package main
import (
"bufio"
"fmt"
irc "go.gianarb.it/irc"
parser "gopkg.in/sorcix/irc.v2"
"log"
"net/textproto"
"time"
)
func main() {
// don't forget to `go get "gopkg.in/sorcix/irc.v2"`
// and to run Tor
bot := irc.NewBot(
"127.0.0.1:9050",
"freenodeok2gncmy.onion:6667",
"MySuperBot",
"MySuperBot",
"#go-nuts",
"",
)
conn, _ := bot.Connect()
defer conn.Close()
verbose := false
reader := bufio.NewReader(conn)
tp := textproto.NewReader(reader)
for {
line, err := tp.ReadLine()
if err != nil {
log.Fatal("unable to connect to IRC server ", err)
}
message := parser.ParseMessage(line)
if verbose {
fmt.Printf("%v \n", message)
}
if message.Command == "PING" {
bot.Send(fmt.Sprint("PONG %d", time.Now().UnixNano()))
}
if message.Command == "PRIVMSG" {
if message.Params[0] == bot.Nick {
// this private message is of the bot
msg := message.Params[1]
// fmt.Println(msg)
// Do Something with this msg
}
}
}
}
```