├── .github └── workflows │ └── go.yml ├── .gitignore ├── LICENSE ├── README.md ├── builds ├── copypasta-linux ├── copypasta-mac └── copypasta-windows └── main.go /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | name: Build 13 | runs-on: ubuntu-latest 14 | steps: 15 | 16 | - name: Set up Go 1.13 17 | uses: actions/setup-go@v1 18 | with: 19 | go-version: 1.13 20 | id: go 21 | 22 | - name: Check out code into the Go module directory 23 | uses: actions/checkout@v2 24 | 25 | - name: Get dependencies 26 | run: | 27 | go get -v -t -d ./... 28 | if [ -f Gopkg.toml ]; then 29 | curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 30 | dep ensure 31 | fi 32 | 33 | - name: Build 34 | run: go build -v . 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # ide stuff 15 | .idea 16 | 17 | # build 18 | Dank-Memer-CLI -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Dank Memer Discord 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dank Memer CLI (copypasta) 2 | Ever wanted to see a random "copypasta" in your command line? Well now you can! 3 | 4 | Binaries are in /builds for you to use! 5 | 6 | ## TODO 7 | 8 | - [x] Ignore texts that are images and don't have the "selftext" field 9 | - [x] The random number should probably take the above into account and not choose between 100, but rather how many text posts there are. 10 | -------------------------------------------------------------------------------- /builds/copypasta-linux: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DankMemer/copypasta-cli/0e2b9d935a8403708f48332cb873b4668e1ab7b9/builds/copypasta-linux -------------------------------------------------------------------------------- /builds/copypasta-mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DankMemer/copypasta-cli/0e2b9d935a8403708f48332cb873b4668e1ab7b9/builds/copypasta-mac -------------------------------------------------------------------------------- /builds/copypasta-windows: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DankMemer/copypasta-cli/0e2b9d935a8403708f48332cb873b4668e1ab7b9/builds/copypasta-windows -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "io/ioutil" 6 | "log" 7 | "math/rand" 8 | "net/http" 9 | "time" 10 | "github.com/danielchatfield/go-chalk" 11 | ) 12 | 13 | type ShitPost struct { 14 | Data struct { 15 | Children []struct { 16 | Post struct { 17 | Title string `json:"title"` 18 | Text string `json:"selftext"` 19 | } `json:"data"` 20 | } `json:"children"` 21 | } `json:"data"` 22 | } 23 | 24 | func main() { 25 | 26 | httpclient := &http.Client{} 27 | 28 | req, err := http.NewRequest("GET", "https://www.reddit.com/r/copypasta/top/.json?sort=top&t=week&showmedia=false&mediaonly=false&is_self=true&limit=100", nil) 29 | 30 | if err != nil { 31 | log.Println("error:", err) 32 | return 33 | } 34 | 35 | req.Header.Add("User-Agent", "Meme-cli") 36 | 37 | res, err := httpclient.Do(req) 38 | 39 | if err != nil { 40 | log.Println("error:", err) 41 | return 42 | } 43 | if res.StatusCode != 200 { 44 | log.Fatalln("Non-OK Status:", res.Status) 45 | } 46 | 47 | body, err := ioutil.ReadAll(res.Body) 48 | if err != nil { 49 | log.Println("error:", err) 50 | return 51 | } 52 | 53 | s, err := getData([]byte(body)) // turn the JSON response into a struct 54 | 55 | rand.Seed(time.Now().UnixNano()) // Seed the random number 56 | randomPost := rand.Intn(100 - 1) + 1 // TODO: make the first number (max) depend on how many "Children" structs are returned 57 | 58 | post := s.Data.Children[randomPost].Post 59 | log.Println(chalk.Yellow(post.Title), "\n", 60 | chalk.Blue(post.Text)) 61 | } 62 | 63 | func getData(body []byte) (*ShitPost, error) { 64 | var s = new(ShitPost) 65 | err := json.Unmarshal(body, &s) 66 | if err != nil { 67 | log.Println("error:", err) 68 | } 69 | return s, err 70 | } --------------------------------------------------------------------------------