stalkr / goircbot Goto Github PK
View Code? Open in Web Editor NEWGo IRC Bot
Home Page: https://godoc.org/github.com/StalkR/goircbot
License: Apache License 2.0
Go IRC Bot
Home Page: https://godoc.org/github.com/StalkR/goircbot
License: Apache License 2.0
If connection drops, e.g. with irc server showing the bot is gone or by issuing a kill, the bot doesn't seem to realize.
I'm expecting a log like: Connection error: dial tcp xxxxxxxxxxxxx - reconnecting in 1 minute
The "disconnected" handler at bot/bot.go:71 rebuilds b.channels from b.Me().Channels() before quitting - presumably, the intent of this is to preserve the effect of joins and parts that have happened since the bot was connected. However, b.Me().Channels() appears to be empty when this handler is run, so the actual effect is to stop the bot from joining any channels at all on reconnection.
Keeping b.channels up to date is probably the right solution in general; my use case is a static list of channels and a long-lived bot, so I can just remove the logic entirely.
Using the example bot, with the df limit altered so it fires, I see:
$ go run -race examplebot.go -host localhost:6667 -channels "#test"
...
WARNING: DATA RACE
Write by goroutine 77:
runtime.mapassign1()
/home/michael/work/topics/golang/go/src/runtime/hashmap.go:374 +0x0
github.com/fluffle/goirc/state.(*Nick).addChannel()
~/golang/src/github.com/fluffle/goirc/state/nick.go:73 +0x151
github.com/fluffle/goirc/state.(*stateTracker).Associate()
~/golang/src/github.com/fluffle/goirc/state/tracker.go:214 +0x3ad
github.com/fluffle/goirc/client.(*Conn).h_JOIN()
~/golang/src/github.com/fluffle/goirc/client/state_handlers.go:77 +0x665
github.com/fluffle/goirc/client.HandlerFunc.Handle()
~/golang/src/github.com/fluffle/goirc/client/dispatch.go:24 +0x43
github.com/fluffle/goirc/client.(*hNode).Handle()
~/golang/src/github.com/fluffle/goirc/client/dispatch.go:52 +0xc8
github.com/fluffle/goirc/client.func·002()
~/golang/src/github.com/fluffle/goirc/client/dispatch.go:128 +0x1c4
Previous read by goroutine 6:
github.com/fluffle/goirc/state.(*Nick).Channels()
~/golang/src/github.com/fluffle/goirc/state/nick.go:124 +0x81
github.com/StalkR/goircbot/plugins/df.(*Alarm).Notify()
~/golang/src/github.com/StalkR/goircbot/plugins/df/handlers.go:62 +0x315
github.com/StalkR/goircbot/plugins/df.(*Alarm).Monitor()
~/golang/src/github.com/StalkR/goircbot/plugins/df/handlers.go:46 +0x2c5
Goroutine 77 (running) created at:
github.com/fluffle/goirc/client.(*hSet).dispatch()
~/golang/src/github.com/fluffle/goirc/client/dispatch.go:130 +0x32c
github.com/fluffle/goirc/client.(*Conn).dispatch()
~/golang/src/github.com/fluffle/goirc/client/dispatch.go:161 +0x5a
github.com/fluffle/goirc/client.(*Conn).runLoop()
~/golang/src/github.com/fluffle/goirc/client/connection.go:316 +0x131
Goroutine 6 (running) created at:
github.com/StalkR/goircbot/plugins/df.Register()
~/golang/src/github.com/StalkR/goircbot/plugins/df/handlers.go:97 +0x15c
main.main()
~/golang/src/github.com/StalkR/goircbot/examplebot.go:63 +0x5c4
This seems to be a basic problem with anything that sends from another goroutine.
I guess the best fix is in goirc, so close this if you like, but I thought I'd at least document it for others.
i'd like to use a different character than !
.
being able to override all of the command handler would be nice, but if not, a method on Bot or Commands to set the command prefix to e.g. .
would do.
I'd like to set the server password. fluffle/goirc supports it, but your NewBot* functions does not. Would you be up for adding (having that added)? It'd break the API as it stands...
Btw I'm using goircbot for a git* webhook receiving bot; https://github.com/quite/pjodd
But perhaps I'm slowly growing out of goircbot... thinking of multi-network support currently :)
NewBot API supports a single hostname (https://github.com/StalkR/goircbot/blob/master/bot/bot.go#L35), we'll need to change that, possibly introducing a slice of host, port and SSL (maybe in a string if we use host:+port format where + is optional for SSL).
And to be able to reconnect, we'll need to keep that slice somewhere in BotImpl https://github.com/StalkR/goircbot/blob/master/bot/bot.go#L99
goirc client.Config struct supports a single hostname (https://github.com/fluffle/goirc/blob/master/client/connection.go#L65). Possibly we can keep that.
We'll need to think carefully about this as it's a breaking API change, so I'd prefer to get it right first time.
$ go get github.com/StalkR/goircbot
go: github.com/StalkR/[email protected] requires
github.com/StalkR/[email protected] requires
github.com/StalkR/[email protected]: reading github.com/StalkR/aecache/go.mod at revision v1.0.1: unknown revision v1.0.1
Probably related to #8
$ go run -race ~/go/src/github.com/StalkR/goircbot/examplebot.go -host=xxxxx -channels=#xxxxx -nick=xxxxx
==================
WARNING: DATA RACE
Write by goroutine 37:
github.com/fluffle/goirc/client.(*Conn).Me()
~/go/src/github.com/fluffle/goirc/client/connection.go:175 +0xf0
github.com/StalkR/goircbot/plugins/renick.func·001()
~/go/src/github.com/StalkR/goircbot/plugins/renick/handlers.go:25 +0x47
github.com/fluffle/goirc/client.HandlerFunc.Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:24 +0x44
github.com/fluffle/goirc/client.(*hNode).Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:52 +0xcf
github.com/fluffle/goirc/client.func·002()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:128 +0x208
Previous write by goroutine 36:
github.com/fluffle/goirc/client.(*Conn).Me()
~/go/src/github.com/fluffle/goirc/client/connection.go:175 +0xf0
github.com/StalkR/goircbot/bot.func·002()
~/go/src/github.com/StalkR/goircbot/bot/bot.go:68 +0x151
github.com/fluffle/goirc/client.HandlerFunc.Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:24 +0x44
github.com/fluffle/goirc/client.(*hNode).Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:52 +0xcf
github.com/fluffle/goirc/client.func·002()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:128 +0x208
Goroutine 37 (running) created at:
github.com/fluffle/goirc/client.(*hSet).dispatch()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:130 +0x39a
github.com/fluffle/goirc/client.(*Conn).dispatch()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:169 +0xcf
github.com/fluffle/goirc/client.(*Conn).h_001()
~/go/src/github.com/fluffle/goirc/client/handlers.go:46 +0x150
github.com/fluffle/goirc/client.HandlerFunc.Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:24 +0x44
github.com/fluffle/goirc/client.(*hNode).Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:52 +0xcf
github.com/fluffle/goirc/client.func·002()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:128 +0x208
Goroutine 36 (finished) created at:
github.com/fluffle/goirc/client.(*hSet).dispatch()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:130 +0x39a
github.com/fluffle/goirc/client.(*Conn).dispatch()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:169 +0xcf
github.com/fluffle/goirc/client.(*Conn).h_001()
~/go/src/github.com/fluffle/goirc/client/handlers.go:46 +0x150
github.com/fluffle/goirc/client.HandlerFunc.Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:24 +0x44
github.com/fluffle/goirc/client.(*hNode).Handle()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:52 +0xcf
github.com/fluffle/goirc/client.func·002()
~/go/src/github.com/fluffle/goirc/client/dispatch.go:128 +0x208
==================
To pick up the last commit
Originally posted by @quite in #23 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.