Browse Source

bot: Added !register command.

master 1.0.0
Gisle Aune 5 years ago
parent
commit
31fd9f9a56
  1. 24
      internal/bot/channel.go
  2. 3
      internal/config/config.go

24
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

3
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"`
}
}

Loading…
Cancel
Save