Skip to content

Commit

Permalink
Merge branch 'submit'
Browse files Browse the repository at this point in the history
  • Loading branch information
godwhoa committed Mar 28, 2019
2 parents 12755f0 + ea8c721 commit 4b36a54
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 64 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/godwhoa/oodle/oodle"
"github.com/godwhoa/oodle/plugins/core"
"github.com/godwhoa/oodle/plugins/hackterm"
"github.com/godwhoa/oodle/plugins/oodnet"
"github.com/godwhoa/oodle/plugins/sed"
"github.com/godwhoa/oodle/plugins/urban"
"github.com/godwhoa/oodle/plugins/webhook"
"github.com/godwhoa/oodle/plugins/wiki"
"github.com/godwhoa/oodle/plugins/invite"
_ "github.com/mattn/go-sqlite3"
flag "github.com/ogier/pflag"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -75,8 +75,8 @@ func main() {
urban.Register(deps),
wiki.Register(deps),
sed.Register(deps),
invite.Register(deps),
webhook.Register(deps),
oodnet.Register(deps),
); err != nil {
logger.Fatal(err)
}
Expand Down
62 changes: 0 additions & 62 deletions plugins/invite/invite.go

This file was deleted.

49 changes: 49 additions & 0 deletions plugins/oodnet/submit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package oodnet

import (
"net/url"
"strings"

m "github.com/godwhoa/oodle/middleware"
"github.com/godwhoa/oodle/oodle"
u "github.com/godwhoa/oodle/utils"
"github.com/spf13/viper"
)

func Register(deps *oodle.Deps) error {
checker, bot := deps.IRC, deps.Bot
key := viper.GetString("submit_key")
if key == "" {
return nil
}
bot.RegisterCommands(Submit(checker, key))
return nil
}

func Submit(checker oodle.Checker, key string) oodle.Command {
cmd := oodle.Command{
Prefix: ".",
Name: "submit",
Description: "IDK, ask exezin.",
Usage: ".submit <desc> <url>",
Fn: func(nick string, args []string) (string, error) {
desc := strings.Join(args[:len(args)-1], " ")
rawurl := args[len(args)-1]

if _, err := url.ParseRequestURI(rawurl); err != nil {
return "Last arg. isn't an url", nil
}
form := url.Values{}
form.Set("url", rawurl)
form.Set("username", nick)
form.Set("text", desc)
form.Set("password", key)
_, err := u.HTTPClient.PostForm("https://oods.net/submit.php", form)
if err != nil {
return "Failed to submit: " + err.Error(), nil
}
return "Submitted!", nil
},
}
return m.Chain(cmd, m.MinArg(2), m.RegisteredOnly(checker))
}

0 comments on commit 4b36a54

Please sign in to comment.