From 31fd9f9a5628d7755defe50a56eef56934a55df8 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sun, 2 Dec 2018 18:40:55 +0100 Subject: [PATCH] bot: Added !register command. --- internal/bot/channel.go | 24 ++++++++++++++++++++++-- internal/config/config.go | 3 +++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/internal/bot/channel.go b/internal/bot/channel.go index 55525eb..6a34863 100644 --- a/internal/bot/channel.go +++ b/internal/bot/channel.go @@ -85,8 +85,6 @@ func (channel *Channel) loop() { select { case post := <-channel.ch: { - log.Printf("Received %s post from %s", post.Kind, post.Nick) - // Handle bot commands, or add to queue otherwise. if cmd := post.botCommand(); cmd != nil { switch cmd.Verb { @@ -128,6 +126,25 @@ func (channel *Channel) loop() { log.Println("Could not set event name:", err) } } + case "register": + { + target := channel.client.Channel(channel.name) + if target != nil { + me, ok := target.UserList().User(channel.client.Nick()) + if !ok || !strings.ContainsRune(me.Modes, 'o') { + channel.client.Say(channel.name, "This unit require operator privileges to serve this request.") + break + } + + chanServNick := config.Get().Names.ChanServ + if chanServNick == "" { + channel.client.Say(channel.name, "This function is not enabled.") + break + } + + channel.client.Sayf(chanServNick, "REGISTER %s", target.Name()) + } + } } } else { queue = append(queue, post) @@ -137,6 +154,9 @@ func (channel *Channel) loop() { } } + // Posts after here aren't going to be bot commands, so log its reception. + log.Printf("Received %s post from %s", post.Kind, post.Nick) + // Stop here if there's nothing to post. if len(queue) == 0 { break diff --git a/internal/config/config.go b/internal/config/config.go index 288afcf..7d0dbcf 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -29,6 +29,9 @@ type Config struct { Commands struct { OnJoinOp []string `json:"onJoinOp"` OnReady []string `json:"onReady"` + } `json:"commands"` + Names struct { + ChanServ string `json:"chanserv"` } }