Created
September 2, 2018 18:17
-
-
Save prawnsalad/0fa4a20c8ff075a71b291c54a72570c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"io" | |
"github.com/kiwiirc/webircgateway/pkg/webircgateway" | |
) | |
// The entry point of a plugin. This is called when the plugin is loaded to webircgateway | |
func Start(gateway *webircgateway.Gateway) { | |
println(">", webircgateway.Version) | |
webircgateway.HookRegister("irc.connection.pre", hookIrcConnectionPre) | |
webircgateway.HookRegister("irc.line", hookIrcLine) | |
webircgateway.HookRegister("client.state", hookClientState) | |
gateway.HttpRouter.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { | |
// Attach any HTTP routers here. Mount custom web apps, proxt them elsewhere, etc. | |
w.Header().Set("Content-Type", "text/plain") | |
w.WriteHeader(http.StatusOK) | |
io.WriteString(w, "Hello there!\n") | |
}) | |
} | |
// Called when a client is about to connect to an IRC server | |
func hookIrcConnectionPre(hook *webircgateway.HookIrcConnectionPre) { | |
println(">>>>>>>> pre connection hook") | |
} | |
// Called when a client or IRC server sends an IRC message | |
func hookIrcLine(hook *webircgateway.HookIrcLine) { | |
println(">>>>>", hook.Message.Command) | |
} | |
// Called when a client has connected or disconnected | |
func hookClientState(hook *webircgateway.HookClientState) { | |
if hook.Connected { | |
println(">>>> connected", hook.Client.Id) | |
} else { | |
println(">>>> disconnected", hook.Client.Id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment