makaba

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2021 License: MIT Imports: 13 Imported by: 0

README

Go-Makaba

GopherGoMakaba

GoMakaba - Golang bindings for the 2ch.hk ⚡️ makaba engine API. Ola-la~

Sending posts has never been easier than this. It comes with features:

  • Post() Get() Catalog()
  • Multipart Support - send images and videos from a local file or remote HTTP URL
  • Passcode Only - we do not support captcha, not yet. Get your passcode here
  • more to come.. be wary, lib is in WIP status.

Getting Started

package main

import (
    "github.com/wmw9/go-makaba"
    "log"
    "os"
)

var (
    Passcode = os.Getenv("PASSCODE") // Get it here https://2ch.hk/2ch
)

func main() {
    num, subject, err := makaba.Get("fag").Thread("Подсосов Мэда")
    if err != nil {
        log.Println(err)
    }
    log.Println(num, subject)

    num, err = makaba.Post().Board("fag").Thread(num).Comment("Чмотик, спок").File("https://i.imgur.com/kPZzAro.png").Do(Passcode)
}

Output:

2021/03/13 19:55:58 13564442 Подсосов Мэда тред №4862
2021/03/13 19:56:00 ✔ Posting succeed: map[Error:<nil> Num:1.356656e+07 Status:OK]

Examples

This is what you normally do for a simple post without files:

num, err := makaba.Post().Board("test").Thread("8420").Comment("Test 123").Do(Passcode)

All possible parameters

num, err := makaba.Post().Board("test").Thread("8420").Name("anon").Subject("PEREKAT").Mail("sage").Comment(">>145930").Do(Passcode)

What if you want to create a new threadperekat? Just put "0" in Thread() func.

num, err := makaba.Post().Board("test").Thread("0").Comment("PEREQUATE").Do(Passcode)

What about file attachments? We got it!

num, err := makaba.Post().Board("test").Thread("8420").File("meme.mp4").Do(Passcode)

You can also combine them to send multiple files

num, err := makaba.Post().Board("test").Thread("8420").File("meme.mp4", "https://i.imgur.com/kPZzAro.png").Do(Passcode)

or like this

num, err := makaba.Post().Board("test").Thread("8420").File("yoba.webm").File("karasik.mp4").Do(Passcode)

Find thread using keyword

num, subject, err := makaba.Get("fag").Thread("Подсосов Мэда")

Author

License

GoMakaba is MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyData

type BodyData struct {
	Key   string
	Value string
}

Here we store minimal base fields like board, thread, name, email, subject and comment to make a post

type CatalogJSON

type CatalogJSON struct {
	Board     string `json:"board"`
	BoardInfo string `json:"BoardInfo"`
	Threads   []struct {
		Comment    string      `json:"comment"`
		Lasthit    int         `json:"lasthit"`
		Num        string      `json:"num"`
		PostsCount int         `json:"posts_count"`
		Score      json.Number `json:"score"`
		Subject    string      `json:"subject"`
		Timestamp  int         `json:"timestamp"`
		Views      int         `json:"views"`
	} `json:"threads"`
}

type FileData

type FileData struct {
	Filename  string
	Fieldname string
	Data      []byte
}

For file attachments like .jpg, .webm .mp4, etc to upload with your post

type GetData

type GetData struct {
	Board       string
	CatalogJSON CatalogJSON
	Num         int
	Errors      []error
}

func Get

func Get(board string) *GetData

Used to create a new Catalog object

func (*GetData) Catalog

func (g *GetData) Catalog(params ...string) *GetData

func (*GetData) Thread

func (g *GetData) Thread(keyword string) (string, string, error)

type Request

type Request *http.Request

type Response

type Response *http.Response

type SuperAgent

type SuperAgent struct {
	Passcode string
	Cookies  []*http.Cookie
	BodyData map[string]string
	FileData []FileData
	Client   *http.Client
	Errors   []error
}

A SuperAgent is an object storing all required request data

func Post

func Post() *SuperAgent

Used to create a new SuperAgent object

func (*SuperAgent) Board

func (p *SuperAgent) Board(board string) *SuperAgent

Used to set board field. Required.

func (*SuperAgent) Comment

func (p *SuperAgent) Comment(comment string) *SuperAgent

Used to set comment field, this is where your post text goes

func (*SuperAgent) Do

func (p *SuperAgent) Do(passcode string) (string, error)

Do() is the most important function that you need to call when ending the chain. The request won't proceed without calling it.

func (*SuperAgent) File

func (p *SuperAgent) File(file ...interface{}) *SuperAgent

File() accepts string as path to a local file or remote HTTP URL. Example: File("1.png") or File("https://i.imgur.com/1.png") or File("1.jpg", "https://i.imgur.com/1.png")

func (*SuperAgent) Mail

func (p *SuperAgent) Mail(mail string) *SuperAgent

Used to set email field

func (*SuperAgent) MakeRequest

func (p *SuperAgent) MakeRequest() (*http.Request, error)

func (*SuperAgent) Name

func (p *SuperAgent) Name(name string) *SuperAgent

Used to set name field

func (*SuperAgent) PasscodeAuth

func (p *SuperAgent) PasscodeAuth(passcode string) bool

Used to authorize passcode into usercode to use it later with HTTP cookie to bypass CAPTCHA. Details https://2ch.hk/2ch

func (*SuperAgent) Subject

func (p *SuperAgent) Subject(subject string) *SuperAgent

Used to set subject field

func (*SuperAgent) Thread

func (p *SuperAgent) Thread(thread string) *SuperAgent

Used to set thread number field. Required. Leave it empty or set 0 to create new thread

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL