From ee6f23e78725b889540751b46acf41974efea01a Mon Sep 17 00:00:00 2001 From: Shin'ya Minazuki Date: Fri, 2 Jan 2026 19:34:10 -0300 Subject: [PATCH] =?UTF-8?q?=E3=81=AF=E3=81=98=E3=82=81=E3=81=BE=E3=81=99?= =?UTF-8?q?=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Shin'ya Minazuki --- .gitignore | 1 + README.md | 12 ++++++++++++ Taskfile.yml | 30 ++++++++++++++++++++++++++++++ config.go | 36 ++++++++++++++++++++++++++++++++++++ go.mod | 10 ++++++++++ go.sum | 18 ++++++++++++++++++ main.go | 27 +++++++++++++++++++++++++++ version.go | 17 +++++++++++++++++ 8 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 Taskfile.yml create mode 100644 config.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 version.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f2c73a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/haruhi diff --git a/README.md b/README.md new file mode 100644 index 0000000..d80bbb5 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Haruhi +The (currently non-functioning) IRC bot for the [Unofficial SOS Brigade](https://hikoushiki-sos-dan.host2go.net)'s IRC channel `#sos-dan`, take 3. + +## License +THE UNOFFICIAL SOS BRIGADE PUBLIC LICENSE + --- Version 2 --- + +You are allowed to do literally whatever you want to this code +provided you follow these conditions: + +1. Acknowledge Haruhi Suzumiya as a god +2. You'll be her wallet diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..723bd1f --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,30 @@ +# https://taskfile.dev + +version: '3' + +env: + GO: go + GOTELEMETRY: off + +vars: + IMPORT: git.laidback.moe/shinyoukai/haruhi + VERSION: 0.0.0 +tasks: + default: + cmds: + - task: build + build: + desc: Build the bot + cmds: + - $GO build -v -ldflags='-w -X {{.IMPORT}}.Version=$VERSION' -buildvcs=false -o haruhi + silent: true + clean: + desc: Remove generated files + cmds: + - rm -f haruhi + silent: true + tidy: + desc: Update go.mod + cmds: + - $GO mod tidy + silent: true diff --git a/config.go b/config.go new file mode 100644 index 0000000..2f7be0a --- /dev/null +++ b/config.go @@ -0,0 +1,36 @@ +package main + +import ( + "log" + "os" + "gopkg.in/ini.v1" +) + +var Config struct { + Channel string + Host string + Nick string +} + +func ConfInit() { + config, err := os.UserConfigDir() + if err != nil { + log.Println("Unable to obtain user's configuration directory") + log.Fatal(err) + } + configPath := config + "/haruhi.ini" + Parse(configPath) +} + +func Parse(file string) error { + cfg, err := ini.Load(file) + if err != nil { + return err + } + + Config.Channel = cfg.Section("haruhi").Key("channel").String() + Config.Host = cfg.Section("haruhi").Key("host").String() + Config.Nick = cfg.Section("haruhi").Key("nick").String() + + return nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3e6aeeb --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module git.laidback.moe/shinyoukai/haruhi + +go 1.25.2 + +require ( + golang.zx2c4.com/irc v0.0.0-20211018023802-6d08d74c58ff + gopkg.in/ini.v1 v1.67.0 +) + +require github.com/stretchr/testify v1.8.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8568377 --- /dev/null +++ b/go.sum @@ -0,0 +1,18 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +golang.zx2c4.com/irc v0.0.0-20211018023802-6d08d74c58ff h1:SxDqMvV5GQ0YrUGCOOJxEnjV+mEP0FTcD9AhyK8yQDk= +golang.zx2c4.com/irc v0.0.0-20211018023802-6d08d74c58ff/go.mod h1:dYOYwwLlPFLQ7C5+M6V39tdhXMiD2JEDXIpQiUgz+Do= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..678855b --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "golang.zx2c4.com/irc/hbot" + "strings" + "time" +) + +func init() { + ConfInit() +} + +func main() { + bot := hbot.NewBot(&hbot.Config{ + Host: string(Config.Host), + Nick: string(Config.Nick), + Channels: strings.Split(Config.Channel, ","), + }) + fmt.Println("Starting haruhi") + fmt.Printf("-- Version: %s -- \n", FullVersion()) + fmt.Printf("Joining %s as %s at %s\n", Config.Host, Config.Nick, Config.Channel) + for { + bot.Run() + time.Sleep(time.Second + 5) + } +} diff --git a/version.go b/version.go new file mode 100644 index 0000000..6b53525 --- /dev/null +++ b/version.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" +) + +var ( + Revision = "0" + Version = "0" +) + +func FullVersion() string { + return fmt.Sprintf("%s (r%s)", Version, Revision) +} +func PrintVersion() string { + return fmt.Sprintf("%s", Version) +}