bot: Added !register command.
the build was successful

This commit is contained in:
2018-12-02 18:40:55 +01:00
parent e68503c72e
commit 31fd9f9a56
2 changed files with 25 additions and 2 deletions
+22 -2
View File
@@ -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
View File
@@ -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"`
}
}