Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpiontek/bitter-irc
Bitter IRC is a streamlined IRC library specifically designed for Twitch IRC servers written in Go (golang).
https://github.com/jpiontek/bitter-irc
bot twitch twitch-irc
Last synced: 26 days ago
JSON representation
Bitter IRC is a streamlined IRC library specifically designed for Twitch IRC servers written in Go (golang).
- Host: GitHub
- URL: https://github.com/jpiontek/bitter-irc
- Owner: jpiontek
- License: mit
- Created: 2016-09-15T00:28:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-27T03:55:37.000Z (over 7 years ago)
- Last Synced: 2024-08-03T13:01:48.984Z (4 months ago)
- Topics: bot, twitch, twitch-irc
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-twitch-dev - jpiontek/bitter-irc - Bitter IRC is a streamlined IRC library specifically designed for Twitch IRC servers written in Go. (Libraries / Golang)
README
# BitterBot IRC Client
Bitter IRC is a streamlined IRC library specifically designed for Twitch's IRC servers.
To see an example application go [here](https://github.com/jpiontek/bitter-irc-example).## Example
```go
import "github.com/jpiontek/bitter-irc"// Your OAuth Key
oauthKey := "my_oauth_key"
// Your account username
username := "fred_bot"
// The channel you'd like to listen to
channelName := "awesome_streamer"
// Use TLS
tls := true// Create a new channel by supplying the necessary info and the Logger digester.
channel := birc.NewTwitchChannel(channelName, username, oauthKey, tls, birc.Logger)// Connect estblishes the underlying TCP connection
err := channel.Connect()
if err != nil {
// Handle error
}// Authenticate will send the proper credentials and join the channel.
err := channel.Authenticate()
if err != nil {
// Handle error
}// Listen begins listening on the channel and handling messages. It is blocking,
// so you may want to wrap it in a go routine if you intend to continue executing
// on the current thread.
err := channel.Listen()
if err != nil {
// Channel eventually had an error.
}
```## Digesters
Digesters are simply functions used to handle incoming IRC messages. They have the signature:
```go
type Digester func(m Message, c ChannelWriter)
```You can pass in any number of digesters to the NewTwitchChannel function. They **MUST** be threadsafe as
they will be called by multiple go routines. An example of the Logger digester:```go
func Logger(m Message, w ChannelWriter) {
if m.Username != "" && m.Content != "" {
fmt.Printf("\n%s %s: %s", m.Time.Format(timeFormat), m.Username, m.Content)
}
}
```You can see the Logger digester just prints a formatted string to stdout if the message has a username and
some sort of content.The ChannelWriter is an interface that represents a channel you can write to via the Send function.
```go
// Simply checks if the content of someone's message is !command. If so then
// the digester replies in the channel with "Executing command!".
if m.Content == "!command" {
w.Send("Executing command!")
}
```The ChannelWriter also supports SendMessage. You can send any message struct
via this function.```go
message := &birc.Message{
Command: "PONG",
Content: "tmi.twitch.tv",
}err := w.SendMessage(message)
```The ChannelWriter also supports retrieving the Channel's configuration.
```go
config := w.GetConfig()
```The Message struct passed into each digester:
```go
type Message struct {
Name string
Username string
Content string
Command string
Host string
Params []string
Time time.Time
}
```