gokoreanbots

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: MIT Imports: 7 Imported by: 1

README

gokoreanbots

Go 전용 한국 디스코드 봇 리스트 SDK

서버 수 업데이트와 투표 확인 기능을 지원합니다. (랭킹 불러오기 지원 예정)

Docs

설치 방법

go get github.com/simsimler/gokoreanbots

사용 방법

  1. 서버 수 업데이트만 할 경우
package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"

	"github.com/bwmarrin/discordgo"
	"github.com/simsimler/gokoreanbots"
)

func main() {
	session, _ := discordgo.New("DISCORD BOT TOKEN")
	err := session.Open()
	if err != nil {
		log.Panicln(err)
	}
	gokoreanbots.NewKoreanbots(session, "KOREANBOTS TOKEN", true)
	fmt.Println(session.State.User.Username + "(으)로 로그인했습니다.")
	sc := make(chan os.Signal)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
	<-sc
}

  1. 투표 여부 불러오기
package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"

	"github.com/bwmarrin/discordgo"
	"github.com/simsimler/gokoreanbots"
)

var (
	session, _ = discordgo.New("DISCORD BOT TOKEN")
	koreanbots = gokoreanbots.NewKoreanbots(session, "KOREANBOTS TOKEN", false)
)

func main() {
	err := session.Open()
	if err != nil {
		log.Panicln(err)
	}
	fmt.Println(session.State.User.Username + "(으)로 로그인했습니다.")
	session.AddHandler(messageCreate)
	sc := make(chan os.Signal)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
	<-sc
}

func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
	if s.State.User.ID == m.Author.ID {
		return
	}
	switch m.Content {
	case "!votecheck":
		vote, _ := koreanbots.GetVote(m.Author.ID)
		if vote.Voted {
			_, _ = s.ChannelMessageSend(m.ChannelID, "하트를 누르셨군요")
		} else {
			_, _ = s.ChannelMessageSend(m.ChannelID, "하트를 누르지 않으셨군요")
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadRequest returned when sent wrong body
	ErrBadRequest = errors.New("400 Bad Request")
	// ErrForbidden returned when get wrong Authorization header
	ErrForbidden = errors.New("403 Forbidden")
	// ErrRateLimited returned when rate limited.
	ErrRateLimited = errors.New("429 Too Many Request")
	// ErrUnknownStatusCode returned when status code is not 200 or not defined as error
	ErrUnknownStatusCode = errors.New("api returned unknown status code")
)

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Response

	ID          string     `json:"id"`
	Flags       int        `json:"flags"`
	Owners      []BotOwner `json:"owners"`
	Library     string     `json:"lib"`
	Prefix      string     `json:"prefix"`
	Votes       int        `json:"votes"`
	Servers     int        `json:"servers"`
	Intro       string     `json:"intro"`
	Description string     `json:"desc"`
	Web         string     `json:"web"`
	Git         string     `json:"git"`
	Url         string     `json:"url"`
	Category    []string   `json:"category"`
	Status      string     `json:"status"`
	Discord     string     `json:"discord"`
	State       string     `json:"state"`
	Vanity      string     `json:"vanity"`
	Background  string     `json:"bg"`
	Banner      string     `json:"banner"`
	Tag         string     `json:"tag"`
	Avatar      string     `json:"avatar"`
	Name        string     `json:"name"`
	// contains filtered or unexported fields
}

Bot is what registered in Koreanbots

func (Bot) GetRaw

func (v Bot) GetRaw() *RawResponse

type BotOwner

type BotOwner struct {
	Response

	Id       string   `json:"id"`
	Flags    int      `json:"flags"`
	Github   string   `json:"github"`
	Tag      string   `json:"tag"`
	Username string   `json:"username"`
	Bots     []string `json:"bots"`
	// contains filtered or unexported fields
}

BotOwner is owner of bot

func (BotOwner) GetRaw

func (v BotOwner) GetRaw() *RawResponse

type BotStatRequest

type BotStatRequest struct {
	Servers int `json:"servers"`
	Shards  int `json:"shards"`
}

BotStatRequest is body model of bot's stats endpoint

type Bots

type Bots struct {
	Type        string `json:"type"`
	Data        []Bot  `json:"data"`
	CurrentPage int    `json:"currentPage"`
	TotalPage   int    `json:"totalPage"`
	// contains filtered or unexported fields
}

Bots are what registered in Koreanbots

func (Bots) GetRaw

func (v Bots) GetRaw() *RawResponse

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient() *HTTPClient

NewHTTPClient create new http client

func (*HTTPClient) GetBot added in v1.2.2

func (c *HTTPClient) GetBot(id string) (*Bot, error)

func (*HTTPClient) GetBotsByVote

func (c *HTTPClient) GetBotsByVote(page int) (*Bots, error)

GetBotsByVote gets bots by vote in koreanbots

func (*HTTPClient) GetNewBots

func (c *HTTPClient) GetNewBots() (*Bots, error)

GetNewBots gets new bots from koreanbots

func (*HTTPClient) GetUser added in v1.2.2

func (c *HTTPClient) GetUser(id string) (*User, error)

GetUser get koreanbots user

func (*HTTPClient) GetVote

func (c *HTTPClient) GetVote(token, botID, userID string) (*Vote, error)

GetVote gets vote of user from koreanbots

func (*HTTPClient) PostServers

func (c *HTTPClient) PostServers(token, botID string, servers, shards int) error

PostServers post servers to koreanbots

func (*HTTPClient) SearchBots

func (c *HTTPClient) SearchBots(query string, page int) (*Bots, error)

SearchBots searches bots from koreanbots

type Koreanbots

type Koreanbots struct {
	// contains filtered or unexported fields
}

func NewKoreanbots

func NewKoreanbots(session *discordgo.Session, token string, postServers bool) *Koreanbots

NewKoreanbots creates new Koreanbots client

func (Koreanbots) GetVote

func (k Koreanbots) GetVote(userID string) (*Vote, error)

GetVote gets vote of user from koreanbots

func (Koreanbots) PostServers

func (k Koreanbots) PostServers() error

PostServers post servers to koreanbots

type RawResponse

type RawResponse struct {
	Code    int             `json:"code"`
	Data    json.RawMessage `json:"data"`
	Version int             `json:"version"`
}

RawResponse is raw value of response. You can get this by (Response).GetRaw()

type Response

type Response interface {
	// GetRaw return raw response
	GetRaw() *RawResponse
}

Response is interface of typed response models

type User added in v1.2.2

type User struct {
	Response

	ID       string `json:"id"`
	Flags    int    `json:"flags"`
	Github   string `json:"github"`
	Tag      string `json:"tag"`
	Username string `json:"username"`
	Bots     []Bot  `json:"bots"`
	// contains filtered or unexported fields
}

func (User) GetRaw added in v1.2.2

func (u User) GetRaw() *RawResponse

type Vote

type Vote struct {
	Response

	Voted    bool  `json:"voted"`
	LastVote int64 `json:"lastVote"`
	// contains filtered or unexported fields
}

Vote is response of (bot/server)'s vote endpoint

func (Vote) GetRaw

func (v Vote) GetRaw() *RawResponse

Jump to

Keyboard shortcuts

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