discordconnect

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

README

Discord Connect

Implements Discord OAUTH2 within ease. OOP-like API!

Explore API

Documentation

Download

go get github.com/Z3NTL3/discord-connect

Example
package main

import (
	"fmt"
	"log"
	"reflect"
	"time"

	discordconnect "github.com/Z3NTL3/discord-connect"
)

func main() {
	application := discordconnect.AppContext{
		// Dummy app context
		Client_id: "1131879305987760208",
		Client_secret: "9spr9szfgLvEsV0TjsqH0OaIJ97lVjMR",
		Code: "7ey3za64UPN4DA0xgIYTAGZ4HKSWOW",
		Grant_type: "authorization_code",
		Redirect_uri: "http://localhost:2000/api/v1/discord/callback",
	}

	client := discordconnect.Initialize(time.Duration(time.Second * 5), application)
	
	// client.SetProxy("http://root:root@localhost:9050")
	err, resp := client.Connect(); if err != nil {
		log.Fatal(err)
	}

	ctx := reflect.ValueOf(*resp)
	for i := 0; i < ctx.NumField(); i++ {
		if ctx.Field(i).CanInt() {
			fmt.Println("["+ctx.Type().Field(i).Name+"]", ctx.Field(i).Int())
			continue
		}

		fmt.Println("["+ctx.Type().Field(i).Name+"]", ctx.Field(i).String())
	}
}

Documentation

Index

Constants

View Source
const (
	DISCORD_OAUTH2_TOKEN_URL string = "https://discord.com/api/oauth2/token"
)

Variables

View Source
var (
	DEFAULT_UA string = "" /* 139-byte string literal not displayed */
)

Functions

func Initialize

func Initialize(timeout time.Duration, appCtx AppContext) *client

Initializes the client

Types

type AppContext

type AppContext struct {
	Client_id     string `client_id`
	Client_secret string `client_secret`
	Grant_type    string `grant_type`
	Code          string `code`
	Redirect_uri  string `redirect_uri`
}

Context for your Discord application

func (*AppContext) Change_ClientID

func (app *AppContext) Change_ClientID(id string)

func (*AppContext) Change_ClientSecret

func (app *AppContext) Change_ClientSecret(secret string)

func (*AppContext) Change_Code

func (app *AppContext) Change_Code(code string)

func (*AppContext) Change_GrantType

func (app *AppContext) Change_GrantType(grant_type string)

func (*AppContext) Change_REDIR_URI

func (app *AppContext) Change_REDIR_URI(redir_uri string)

type Response

type Response struct {
	Token        Token  `json:"access_token"`
	Type         string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken Token  `json:"refresh_token"`
	Scope        string `json:"scope"`
}

Discord API response after “authorization_code“ exchange

type Token

type Token string

Jump to

Keyboard shortcuts

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