Merge pull request #22 from arachnist/missing-plugins

Added missing plugins.
configurable-file-paths
Robert S. Gerus 2015-11-29 21:12:54 +01:00
commit de569529f0
6 changed files with 217 additions and 0 deletions

36
bot/bonjour.go Normal file
View File

@ -0,0 +1,36 @@
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bot
import (
"fmt"
"math/rand"
"strings"
"time"
"github.com/arachnist/gorepost/irc"
)
func bonjour(output func(irc.Message), msg irc.Message) {
var rmsg string
if strings.Split(msg.Trailing, " ")[0] != ":bonjour" {
return
}
img, err := httpGetXpath("http://www.bonjourmadame.fr/page/"+fmt.Sprintf("%d", rand.Intn(2370)+1), "//div[@class='photo post']//img/@src")
if err != nil {
rmsg = fmt.Sprint("error:", err)
} else {
rmsg = "bonjour (nsfw): " + img
}
output(reply(msg, rmsg))
}
func init() {
rand.Seed(time.Now().UnixNano())
addCallback("PRIVMSG", "bonjour", bonjour)
}

37
bot/cycki.go Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bot
import (
"fmt"
"regexp"
"strings"
"github.com/arachnist/gorepost/irc"
)
var stripCycki *regexp.Regexp
func cycki(output func(irc.Message), msg irc.Message) {
var rmsg string
if strings.Split(msg.Trailing, " ")[0] != ":cycki" {
return
}
img, err := httpGetXpath("http://oboobs.ru/random/", "//img/@src")
if err != nil {
rmsg = fmt.Sprint("error:", err)
} else {
rmsg = "cycki (nsfw): " + string(stripCycki.ReplaceAll([]byte(img), []byte("")))
}
output(reply(msg, rmsg))
}
func init() {
stripCycki, _ = regexp.Compile("_preview")
addCallback("PRIVMSG", "cycki", cycki)
}

View File

@ -5,9 +5,11 @@
package bot
import (
"bufio"
"errors"
"io"
"net/http"
"os"
"time"
"github.com/moovweb/gokogiri"
@ -94,3 +96,18 @@ func reply(msg irc.Message, text string) irc.Message {
Trailing: text,
}
}
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}

59
bot/jan.go Normal file
View File

@ -0,0 +1,59 @@
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bot
import (
"log"
"math/rand"
"strings"
"time"
"github.com/arachnist/gorepost/irc"
)
var objects []string
var predicates []string
func jan(output func(irc.Message), msg irc.Message) {
args := strings.Split(msg.Trailing, " ")
if args[0] != ":jan" {
return
}
var predicate string
var object string
if len(args) > 1 {
if strings.HasSuffix(args[1], "ł") {
predicate = args[1]
object = objects[rand.Intn(len(objects))]
} else {
object = args[1]
predicate = predicates[rand.Intn(len(predicates))]
}
} else {
predicate = predicates[rand.Intn(len(predicates))]
object = objects[rand.Intn(len(objects))]
}
str := "Jan Paweł II " + predicate + " małe " + object
output(reply(msg, str))
}
func init() {
var err error
rand.Seed(time.Now().UnixNano())
objects, err = readLines("/home/repost/rzeczowniki")
if err != nil {
log.Println("failed to read objects", err)
return
}
predicates, err = readLines("/home/repost/czasowniki")
if err != nil {
log.Println("failed to read predicates", err)
return
}
addCallback("PRIVMSG", "jan", jan)
}

38
bot/papiez.go Normal file
View File

@ -0,0 +1,38 @@
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bot
import (
"log"
"math/rand"
"strings"
"time"
"github.com/arachnist/gorepost/irc"
)
var adverbs []string
func papiez(output func(irc.Message), msg irc.Message) {
args := strings.Split(msg.Trailing, " ")
if args[0] != ":papiez" && args[0] != ":papież" {
return
}
choice := "Papież " + adverbs[rand.Intn(len(adverbs))]
output(reply(msg, choice))
}
func init() {
var err error
rand.Seed(time.Now().UnixNano())
adverbs, err = readLines("/home/repost/przymiotniki")
if err != nil {
log.Println("failed to read adverbs", err)
return
}
addCallback("PRIVMSG", "papiez", papiez)
}

30
bot/pick.go Normal file
View File

@ -0,0 +1,30 @@
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bot
import (
"math/rand"
"strings"
"time"
"github.com/arachnist/gorepost/irc"
)
func pick(output func(irc.Message), msg irc.Message) {
args := strings.Split(msg.Trailing, " ")
if args[0] != ":pick" {
return
}
// don't pick :pick
choice := args[rand.Intn(len(args)-1)+1]
output(reply(msg, choice))
}
func init() {
rand.Seed(time.Now().UnixNano())
addCallback("PRIVMSG", "pick", pick)
}