diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-22 02:31:41 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-22 02:37:17 +0800 |
commit | 9a132559c44f025c0a73915b3fe418751294089b (patch) | |
tree | 64060de02352af533d5df49a07202c57070a3b6b /irc.go | |
parent | errorPage404 should actually do 404 (diff) | |
download | forge-9a132559c44f025c0a73915b3fe418751294089b.tar.gz forge-9a132559c44f025c0a73915b3fe418751294089b.tar.zst forge-9a132559c44f025c0a73915b3fe418751294089b.zip |
Add rudimentary IRC logic
Diffstat (limited to 'irc.go')
-rw-r--r-- | irc.go | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,46 @@ +package main + +import ( + "crypto/tls" + "net" + + "go.lindenii.runxiyu.org/lindenii-irc" +) + +func ircBotSession() error { + var err error + var underlyingConn net.Conn + if config.IRC.TLS { + underlyingConn, err = tls.Dial(config.IRC.Net, config.IRC.Addr, nil) + } else { + underlyingConn, err = net.Dial(config.IRC.Net, config.IRC.Addr) + } + if err != nil { + return (err) + } + conn := irc.NewConn(underlyingConn) + conn.WriteString("NICK forge\r\nUSER forge 0 * :Forge\r\n") + for { + msg, err := conn.ReadMessage() + if err != nil { + return (err) + } + switch msg.Command { + case "001": + conn.WriteString("JOIN #chat\r\n") + case "PING": + conn.WriteString("PONG :") + conn.WriteString(msg.Args[0]) + conn.WriteString("\r\n") + case "JOIN": + conn.WriteString("PRIVMSG #chat :test\r\n") + default: + } + } +} + +func ircBotLoop() { + for { + _ = ircBotSession() + } +} |