Skip to content
This repository was archived by the owner on Sep 4, 2019. It is now read-only.

Commit 4cb2028

Browse files
committed
Merge branch 'feature/help-rewrite' into develop
2 parents 27308b3 + 6cbce36 commit 4cb2028

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CHADEV\_TOKEN | Google Oauth2 refresh token (string)
5555
CHADEV\_ID | Google Oauth2 Client ID (string)
5656
CHADEV\_SECRET | Google Oauth2 Client Secret (string)
5757
CHADEV\_MEETUP | Meetup API Key (string)
58+
CHADEV\_PASTEBIN | Pastebin API Key (string)
5859

5960
## Running the bot
6061

main.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package main
77
import (
88
"fmt"
99
"os"
10-
"time"
1110

1211
"github.com/danryan/hal"
1312
_ "github.com/danryan/hal/adapter/irc"
@@ -17,7 +16,7 @@ import (
1716
)
1817

1918
// VERSION contians the current verison number and revison if need be
20-
const VERSION = "2015-02-19"
19+
const VERSION = "2015-02-21 Alpha"
2120

2221
// handler is an interface for objects to implement in order to respond to messages.
2322
type handler interface {
@@ -49,8 +48,8 @@ var quitHandler = hear(`(.*)+/quit(.*)+`, "quit", "", func(res *hal.Response) er
4948

5049
var helpHandler = hear(`help`, "help", "Displays this message", func(res *hal.Response) error {
5150
helpMsg := []string{
52-
"HAL Chadev IRC Edition build: " + VERSION,
53-
"Supported commands:",
51+
"HAL Chadev IRC Edition build: " + VERSION + "\n",
52+
"Supported commands:\n",
5453
}
5554

5655
for command, message := range helpMessages {
@@ -59,11 +58,14 @@ var helpHandler = hear(`help`, "help", "Displays this message", func(res *hal.Re
5958
}
6059
}
6160

61+
var text string
6262
for _, msg := range helpMsg {
63-
res.Send(msg)
64-
time.Sleep(1 * time.Second)
63+
text = text + msg
6564
}
6665

66+
text = uploadHelpMsg(text)
67+
res.Send(fmt.Sprintf("My usage information can be found at %s", text))
68+
6769
return nil
6870
})
6971

pastebin.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2014-2015 Chadev. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"io/ioutil"
9+
"net/http"
10+
"net/url"
11+
"os"
12+
"strings"
13+
14+
"github.com/danryan/hal"
15+
)
16+
17+
const githubReadme = "https://github.com/chadev/Chadev_ircbot/blob/master/README.md#usage"
18+
19+
func uploadHelpMsg(msg string) string {
20+
resp, err := http.PostForm("http://pastebin.com/api/api_post.php",
21+
url.Values{"api_dev_key": {os.Getenv("CHADEV_PASTEBIN")},
22+
"api_paste_private": {"0"},
23+
"api_paste_name": {"Ash Usage"},
24+
"api_paste_expire_date": {"10M"},
25+
"api_option": {"paste"},
26+
"api_paste_code": {msg}})
27+
if err != nil {
28+
hal.Logger.Error(err)
29+
return githubReadme
30+
}
31+
defer resp.Body.Close()
32+
33+
body, err := ioutil.ReadAll(resp.Body)
34+
if err != nil {
35+
hal.Logger.Error(err)
36+
return githubReadme
37+
}
38+
39+
url := string(body)
40+
41+
if strings.Contains("Bad API request", url) {
42+
hal.Logger.Error(url)
43+
return githubReadme
44+
}
45+
46+
return url
47+
}

pastebin_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2014-2015 Chadev. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"os"
9+
"strings"
10+
"testing"
11+
)
12+
13+
func TestPastetoPastebin(t *testing.T) {
14+
if os.Getenv("CHADEV_PASTEBIN") == "" {
15+
t.Skip("missing pastebin API key skipping tist")
16+
}
17+
18+
u := uploadHelpMsg("This is a test post")
19+
t.Logf("URL: %s", u)
20+
21+
if strings.Contains("github.com", u) {
22+
t.Error("failed to paste to pastebin, fallback url returned")
23+
}
24+
25+
if !validateURL(u) {
26+
t.Error("URL came back as invalide")
27+
}
28+
}

0 commit comments

Comments
 (0)