discordgo_proxy

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 10 Imported by: 0

README

discordgo-proxy

Simple library for discordgo for using SOCKS5/HTTP proxy

Example:

package main

import (
    "os"
    "syscall"

    "github.com/bwmarrin/discordgo"
    dgo_proxy "github.com/infernox-dev/discordgo-proxy"
    // in this example discordgo_proxy imported as dgo_proxy
)

func main() {
    session, err := discordgo.New()
    if err != nil {
        panic(err)
    }

    // proxy
    proxy, err := dgo_proxy.NewProxy(
        "socks5",
        "127.0.0.1",
        1080,
        dgo_proxy.NewPasswordAuth(
            "username",
            "password",
        )
    )

    // proxy from URL without auth
    proxy, err := dgo_proxy.NewProxyFromURL("socks5://127.0.0.1:1080")
    // proxy from URL with auth
    proxy, err := dgo_proxy.NewProxyFromURL("http://username:password@127.0.0.1:8080")

    if err != nil {
        panic(err)
    }

    // set proxy in session
    err := proxy.UpdateSession(session)
    if err != nil {
        panic(err)
    }

    if err := session.Open(); err != nil {
        panic(err)
    }

    sc := make(chan os.Signal, 1)
    signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
    <-sc

    session.Close()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PROXY_SCHEMES []string = []string{"http", "socks5"}
View Source
var RE_PROXY_USERNAME *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z0-9-_\.]+$`)

Functions

This section is empty.

Types

type ConnectionCheckFailed

type ConnectionCheckFailed struct{ ErrorInfo }

type DialerInitFailed

type DialerInitFailed struct{ ErrorInfo }

type ErrorInfo

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

func (*ErrorInfo) Error

func (e *ErrorInfo) Error() string

func (*ErrorInfo) Info

func (e *ErrorInfo) Info() *any

type InvalidPort

type InvalidPort struct{ ErrorInfo }

type InvalidScheme

type InvalidScheme struct{ ErrorInfo }

type InvalidURL

type InvalidURL struct{ ErrorInfo }

type InvalidUsername

type InvalidUsername struct{ ErrorInfo }

type Proxy

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

Proxy server struct. You must create it using following constructors:

  • NewProxy(scheme string, host string, port uint16, auth *ProxyAuth)
  • NewProxyFromURL(url *net/url.Url)
  • NewProxyFromStringURL(url string)

NOTE: If proxy does not use authentication, set "auth" parameter to nil

func NewProxy

func NewProxy(scheme, host string, port uint16, auth *ProxyAuth) (*Proxy, error)

func NewProxyFromStringURL

func NewProxyFromStringURL(u string) (*Proxy, error)

func NewProxyFromURL

func NewProxyFromURL(u *url.URL) (*Proxy, error)

func (*Proxy) Auth

func (p *Proxy) Auth() *ProxyAuth

Returns pointer to ProxyAuth specified in proxy.

func (*Proxy) CheckConnection

func (p *Proxy) CheckConnection(u string) error

func (*Proxy) DialContext

func (p *Proxy) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

func (*Proxy) GetHttpTransport

func (p *Proxy) GetHttpTransport() *http.Transport

func (*Proxy) GetSocks5Dialer

func (p *Proxy) GetSocks5Dialer() (*proxy.Dialer, error)

func (*Proxy) GetStringURL

func (p *Proxy) GetStringURL() string

func (*Proxy) GetURL

func (p *Proxy) GetURL() *url.URL

func (*Proxy) Host

func (p *Proxy) Host() string

Returns proxy IPv4/IPv6 address (example: 1.1.1.1, ::1) or domain name (example: proxy.example.com).

func (*Proxy) Port

func (p *Proxy) Port() uint16

Returns port (integer from 1 to 65535).

func (*Proxy) Scheme

func (p *Proxy) Scheme() string

Returns proxy scheme ("socks5" or "http").

func (*Proxy) UpdateSession

func (p *Proxy) UpdateSession(session *discordgo.Session) error

type ProxyAuth

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

Proxy server authentication. You must create it using following constructors:

  • NewAuth(user string)
  • NewPasswordAuth(user string, password string)

func NewAuth

func NewAuth(user string) (*ProxyAuth, error)

func NewPasswordAuth

func NewPasswordAuth(user, password string) (*ProxyAuth, error)

func (*ProxyAuth) IsPasswordSet

func (a *ProxyAuth) IsPasswordSet() bool

Returns false if password is empty string and true if password is not empty.

func (*ProxyAuth) Password

func (a *ProxyAuth) Password() string

Returns password. If password is empty, empty string will be returned. You can check is password set with getter "ProxyAuth.IsPasswordSet() bool".

func (*ProxyAuth) User

func (a *ProxyAuth) User() string

Returns user name. Can't be empty if authentication field is specified in "Proxy".

Jump to

Keyboard shortcuts

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