Saksuka

package module
v0.0.0-...-7c414e4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 9 Imported by: 0

README

DogeGarden logo

A wrapper for DogeHouse made in Go 💨

discord - users online

Website · Tracker · Discord · Documentation


Need help or support?
Join our Discord.

Done:

  • Websocket connection
  • Api key authentication
  • Event subscription
  • Query ws events
  • About 50% of mutations

TODO:

  • The rest of mutations
  • Whole audio module
  • Docs

Example usage:

package main

import (
	"fmt"
	"github.com/Explooosion-code/Saksuka"
)

func main() {
	retval, err := Saksuka.Auth("your-api-key")
	if err != nil {
		fmt.Println(err.Error())
		return;
	}

	con := Saksuka.Connection{
		AccessToken:  retval.AccessToken,
		RefreshToken: retval.RefreshToken,
	}

	con.OnNewChatMessage(func(event Saksuka.OnNewMessageEvent, err error) {
		if err != nil {
			fmt.Println("New chat message error! " + err.Error());
			return;
		}

		message := Saksuka.TokensToString(event.Msg.Tokens)

		fmt.Println(message)
	});

	con.OnReady(func(event Saksuka.OnReadyEvent, err error) {

		if err != nil {
			fmt.Println("Error while logging in!: " + err.Error())
		}

		fmt.Println("Logged in as: " + event.User.Username)
		rooms, err := con.GetTopPublicRooms(0)
		if err != nil {
			fmt.Println(err.Error())
			return
		}

		info, err := con.JoinRoomAndGetInfo(rooms.Rooms[0].Id)

		if err != nil {
			fmt.Println("Error while joining the room! " + err.Error())
			return
		}

		fmt.Printf("Joined room: %s | User count: %d\n", info.Room.Name, len(info.Users));
	});

	fmt.Println(con.Start()) // This returns an error if present
}

Documentation

Index

Constants

View Source
const (
	Default      ChatMode = "default"
	Disabled     ChatMode = "disabled"
	FollowerOnly ChatMode = "follower_only"

	WhisperPrivacyOn  WhisperPrivacySetting = "on"
	WhisperPrivacyOff WhisperPrivacySetting = "off"
)
View Source
const ConnectionTimeout = time.Second * 15
View Source
const HeartbeatInterval = 8 * time.Second
View Source
const HttpBaseUrl = "https://api.dogehouse.tv"
View Source
const VERSION = "0.0.0"

Some constants

View Source
const WebsocketBaseUrl = "wss://api.dogehouse.tv/socket"

Variables

This section is empty.

Functions

func TokensToString

func TokensToString(tokens []MessageToken) string

Types

type AuthResponse

type AuthResponse struct {
	Username     string `json:"username"`
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`
	Error        string `json:"error"`
}

func Auth

func Auth(apiKey string) (*AuthResponse, error)

type BaseUser

type BaseUser struct {
	Username     string     `json:"username"`
	Online       bool       `json:"online"`
	LastOnline   string     `json:"lastOnline"`
	Id           string     `json:"id"`
	Bio          string     `json:"bio"`
	DisplayName  string     `json:"displayName"`
	AvatarUrl    string     `json:"avatarUrl"`
	BannerUrl    string     `json:"bannerUrl"`
	NumFollowing int        `json:"numFollowing"`
	NumFollowers int        `json:"numFollowers"`
	CurrentRoom  *Room      `json:"currentRoom"`
	BotOwnerId   NullString `json:"botOwnerId"`
}

type BooleanMap

type BooleanMap map[UUID]bool

type ChatMode

type ChatMode string

type Connection

type Connection struct {
	Socket       *websocket.Conn
	AccessToken  string
	RefreshToken string
	Ready        bool
	Connected    bool
	Listeners    []*Listener
	DebugLog     bool
}

func (*Connection) AddSpeaker

func (con *Connection) AddSpeaker(userId string)

func (*Connection) AskToSpeak

func (con *Connection) AskToSpeak()

func (*Connection) Ban

func (con *Connection) Ban(username string, reason string)

func (*Connection) BanFromRoomChat

func (con *Connection) BanFromRoomChat(userId string)

func (*Connection) ChangeModStatus

func (con *Connection) ChangeModStatus(userId string, value bool)

func (*Connection) ChangeRoomCreator

func (con *Connection) ChangeRoomCreator(userId string)

func (*Connection) Close

func (con *Connection) Close()

func (*Connection) CreateRoomFromScheduledRoom

func (con *Connection) CreateRoomFromScheduledRoom(id, name, description string) (Room, error)

func (*Connection) CreateScheduledRoom

func (con *Connection) CreateScheduledRoom(name, description string, scheduledFor time.Time) (*CreateScheduledRoomResponse, error)

func (*Connection) DeleteRoomChatMessage

func (con *Connection) DeleteRoomChatMessage(userId, messageId string)

func (*Connection) DeleteScheduledRoom

func (con *Connection) DeleteScheduledRoom(id string) error

func (*Connection) EditScheduledRoom

func (con *Connection) EditScheduledRoom(id, name, description string, scheduledFor time.Time) (*EditScheduledRoomResponse, error)

func (*Connection) Follow

func (con *Connection) Follow(userId string) error

func (*Connection) GetBlockedFromRoomUsers

func (con *Connection) GetBlockedFromRoomUsers(cursor int) (GetBlockedFromRoomUsersResponse, error)

func (*Connection) GetFollowList

func (con *Connection) GetFollowList(cursor int) (GetFollowListResponse, error)

func (*Connection) GetInviteList

func (con *Connection) GetInviteList(cursor int) (GetFollowListResponse, error)

func (*Connection) GetMyFollowing

func (con *Connection) GetMyFollowing(cursor int) (GetMyFollowingResponse, error)

func (*Connection) GetMyScheduledRoomsAboutToStart

func (con *Connection) GetMyScheduledRoomsAboutToStart(query string) (GetMyScheduledRoomsAboutToStartResponse, error)

func (*Connection) GetScheduledRooms

func (con *Connection) GetScheduledRooms(cursor string, getOnlyMyScheduledRooms bool) (GetScheduledRoomsResponse, error)

func (*Connection) GetTopPublicRooms

func (con *Connection) GetTopPublicRooms(cursor int) (GetTopPublicRoomsResponse, error)

func (*Connection) GetUserProfile

func (con *Connection) GetUserProfile(idOrUsername string) (*UserWithFollowInfo, error)

func (*Connection) InviteToRoom

func (con *Connection) InviteToRoom(userId string)

func (*Connection) JoinRoomAndGetInfo

func (con *Connection) JoinRoomAndGetInfo(roomId string) (JoinRoomAndGetInfoResponse, error)

func (*Connection) LeaveRoom

func (con *Connection) LeaveRoom() (*LeaveRoomResponse, error)

func (*Connection) OnHandRaised

func (con *Connection) OnHandRaised(handler func(event OnHandRaisedEvent, err error))

func (*Connection) OnInvitationToRoom

func (con *Connection) OnInvitationToRoom(handler func(event OnInvitationToRoomEvent, err error))

func (*Connection) OnNewChatMessage

func (con *Connection) OnNewChatMessage(handler func(event OnNewMessageEvent, err error))

Events

func (*Connection) OnNewRoomDetails

func (con *Connection) OnNewRoomDetails(handler func(event OnNewRoomDetailsEvent, err error))

func (*Connection) OnReady

func (con *Connection) OnReady(handler func(event OnReadyEvent, err error))

func (*Connection) OnSpeakerAdded

func (con *Connection) OnSpeakerAdded(handler func(event OnSpeakerAddedEvent, err error))

func (*Connection) OnSpeakerRemoved

func (con *Connection) OnSpeakerRemoved(handler func(event OnSpeakerRemovedEvent, err error))

func (*Connection) OnUserJoinRoom

func (con *Connection) OnUserJoinRoom(handler func(event OnUserJoinRoomEvent, err error))

func (*Connection) OnUserLeaveRoom

func (con *Connection) OnUserLeaveRoom(handler func(event OnUserLeftRoomEvent, err error))

func (*Connection) RoomBan

func (con *Connection) RoomBan(userId string, shouldBanIp bool)

func (*Connection) RoomUpdate

func (con *Connection) RoomUpdate(args RoomUpdateArgs) error

Initialization of RoomUpdateArgs is a pain in the ass but i don't have any ideas how to make is work and not make it even more confusing than it is

func (*Connection) Search

func (con *Connection) Search(query string) (SearchResult, error)

func (*Connection) SendRoomChatMessage

func (con *Connection) SendRoomChatMessage(message string, whisperedTo ...UUID)

func (*Connection) SetDeaf

func (con *Connection) SetDeaf(deaf bool) error

func (*Connection) SetListener

func (con *Connection) SetListener(userId string)

func (*Connection) SetMute

func (con *Connection) SetMute(isMuted bool) error

func (*Connection) SpeakingChange

func (con *Connection) SpeakingChange(value bool)

func (*Connection) Start

func (con *Connection) Start() error

func (*Connection) UnbanFromRoom

func (con *Connection) UnbanFromRoom(userId string) error

func (*Connection) UnbanFromRoomChat

func (con *Connection) UnbanFromRoomChat(userId string)

func (*Connection) UserBlock

func (con *Connection) UserBlock(userId string) error

func (*Connection) UserCreateBot

func (con *Connection) UserCreateBot(username string) (*UserCreateBotResponse, error)

func (*Connection) UserUnblock

func (con *Connection) UserUnblock(userId string) error

type CreateScheduledRoomResponse

type CreateScheduledRoomResponse struct {
	ScheduledRoom ScheduledRoom `json:"scheduledRoom"`
}

type CurrentRoom

type CurrentRoom struct {
	Id                string        `json:"id"`
	Name              string        `json:"name"`
	Description       string        `json:"description"`
	IsPrivate         bool          `json:"isPrivate"`
	NumPeopleInside   int           `json:"numPeopleInside"`
	VoiceServerId     string        `json:"voiceServerId"`
	CreatorId         string        `json:"creatorId"`
	PeoplePreviewList []UserPreview `json:"peoplePreviewList"`
	InsertedAt        string        `json:"inserted_at"`
	ChatMode          ChatMode      `json:"chatMode"`
	ChatThrottle      int           `json:"chatThrottle"`
	Users             []RoomUser    `json:"users"`
	MuteMap           BooleanMap    `json:"muteMap"`
	DeafMap           BooleanMap    `json:"deafMap"`
	ActiveSpeakerMap  BooleanMap    `json:"activeSpeakerMap"`
	AutoSpeaker       bool          `json:"autoSpeaker"`
}

type EditScheduledRoomResponse

type EditScheduledRoomResponse CreateScheduledRoomResponse

type GetBlockedFromRoomUsersResponse

type GetBlockedFromRoomUsersResponse GetInviteListResponse

type GetFollowListResponse

type GetFollowListResponse struct {
	Users      []UserWithFollowInfo `json:"users"`
	NextCursor *int                 `json:"nextCursor"`
}

type GetInviteListResponse

type GetInviteListResponse struct {
	Users      []User `json:"users"`
	NextCursor *int   `json:"nextCursor"`
}

type GetMyFollowingResponse

type GetMyFollowingResponse GetFollowListResponse

type GetMyScheduledRoomsAboutToStartResponse

type GetMyScheduledRoomsAboutToStartResponse struct {
	ScheduledRooms []ScheduledRoom `json:"scheduledRooms"`
}

type GetScheduledRoomsResponse

type GetScheduledRoomsResponse struct {
	NextCursor     NullString      `json:"nextCursor"`
	ScheduledRooms []ScheduledRoom `json:"scheduledRooms"`
}

type GetTopPublicRoomsResponse

type GetTopPublicRoomsResponse struct {
	Rooms      []Room `json:"rooms"`
	NextCursor *int   `json:"nextCursor"`
}

type GetUserProfileResponse

type GetUserProfileResponse struct {
	Rooms []Room `json:"rooms"`
}

type JoinRoomAndGetInfoResponse

type JoinRoomAndGetInfoResponse struct {
	Room             Room       `json:"room"`
	Users            []RoomUser `json:"users"`
	MuteMap          BooleanMap `json:"muteMap"`
	DeafMap          BooleanMap `json:"deafMap"`
	RoomId           UUID       `json:"roomId"`
	ActiveSpeakerMap BooleanMap `json:"activeSpeakerMap"`
}

type LeaveRoomResponse

type LeaveRoomResponse struct {
	RoomId UUID `json:"roomId"`
}

type Listener

type Listener struct {
	Opcode  string                                `json:"opcode"`
	Handler func(listenerHandler ListenerHandler) `json:"handler"`
}

type ListenerHandler

type ListenerHandler struct {
	Data    interface{} `json:"data"`
	FetchId string      `json:"fetchId"`
}

type Message

type Message struct {
	Id          UUID           `json:"id"`
	UserId      UUID           `json:"userId"`
	AvatarUrl   UUID           `json:"avatarUrl"`
	Color       string         `json:"color"`
	DisplayName string         `json:"displayName"`
	Tokens      []MessageToken `json:"tokens"`
	Username    string         `json:"username"`
	Deleted     bool           `json:"deleted"`
	DeleterId   UUID           `json:"deleterId"`
	SentAt      string         `json:"sentAt"`
	IsWhisper   bool           `json:"isWhisper"`
}

type MessageToken

type MessageToken struct {
	T string      `json:"t"`
	V interface{} `json:"v"`
}

func StringToToken

func StringToToken(input string) MessageToken

type NullString

type NullString string

func (NullString) MarshalJSON

func (c NullString) MarshalJSON() ([]byte, error)

func (*NullString) UnmarshalJSON

func (c *NullString) UnmarshalJSON(in []byte) error

type OnHandRaisedEvent

type OnHandRaisedEvent struct {
	UserId UUID `json:"userId"`
}

type OnInvitationToRoomEvent

type OnInvitationToRoomEvent struct {
	Type        string `json:"type"`
	Username    string `json:"username"`
	DisplayName string `json:"displayName"`
	AvatarUrl   string `json:"avatarUrl"`
	BannerUrl   string `json:"bannerUrl"`
	RoomName    string `json:"roomName"`
	RoomId      UUID   `json:"roomId"`
}

type OnNewMessageEvent

type OnNewMessageEvent struct {
	Msg    Message `json:"msg"`
	UserId UUID    `json:"userId"`
}

type OnNewRoomDetailsEvent

type OnNewRoomDetailsEvent struct {
	RoomId       UUID   `json:"roomId"`
	Name         string `json:"name"`
	ChatThrottle int    `json:"chatThrottle"`
	IsPrivate    bool   `json:"isPrivate"`
	Description  string `json:"description"`
}

type OnReadyEvent

type OnReadyEvent struct {
	User User `json:"user"`
}

type OnSpeakerAddedEvent

type OnSpeakerAddedEvent struct {
	UserId  UUID       `json:"userId"`
	MuteMap BooleanMap `json:"muteMap"`
	DeafMap BooleanMap `json:"deafMap"`
}

type OnSpeakerRemovedEvent

type OnSpeakerRemovedEvent OnSpeakerAddedEvent

type OnUserJoinRoomEvent

type OnUserJoinRoomEvent struct {
	User    User       `json:"user"`
	MuteMap BooleanMap `json:"muteMap"`
	DeafMap BooleanMap `json:"deafMap"`
	RoomId  UUID       `json:"roomId"`
}

type OnUserLeftRoomEvent

type OnUserLeftRoomEvent struct {
	RoomId UUID `json:"roomId"`
	UserId UUID `json:"userId"`
}

type PaginatedBaseUsers

type PaginatedBaseUsers struct {
	Users      []BaseUser `json:"users"`
	NextCursor *int       `json:"nextCursor"`
}

type Room

type Room struct {
	Id                string        `json:"id"`
	Name              string        `json:"name"`
	Description       string        `json:"description"`
	IsPrivate         bool          `json:"isPrivate"`
	NumPeopleInside   int           `json:"numPeopleInside"`
	VoiceServerId     string        `json:"voiceServerId"`
	CreatorId         string        `json:"creatorId"`
	PeoplePreviewList []UserPreview `json:"peoplePreviewList"`
	AutoSpeaker       bool          `json:"autoSpeaker"`
	InsertedAt        string        `json:"inserted_at"`
	ChatMode          ChatMode      `json:"chatMode"`
	ChatThrottle      int           `json:"chatThrottle"`
}

type RoomPermissions

type RoomPermissions struct {
	AskedToSpeak bool `json:"askedToSpeak"`
	IsSpeaker    bool `json:"isSpeaker"`
	IsMod        bool `json:"isMod"`
}

type RoomUpdateArgs

type RoomUpdateArgs struct {
	Name         *string   `json:"name,omitempty"`
	Privacy      *string   `json:"privacy,omitempty"`
	ChatThrottle *int      `json:"chatThrottle,omitempty"`
	Description  *string   `json:"description,omitempty"`
	AutoSpeaker  *bool     `json:"autoSpeaker,omitempty"`
	ChatMode     *ChatMode `json:"chatMode,omitempty"`
}

type RoomUser

type RoomUser struct {
	Username        string           `json:"username"`
	Online          bool             `json:"online"`
	LastOnline      string           `json:"lastOnline"`
	Id              string           `json:"id"`
	Bio             string           `json:"bio"`
	DisplayName     string           `json:"displayName"`
	AvatarUrl       string           `json:"avatarUrl"`
	BannerUrl       string           `json:"bannerUrl"`
	NumFollowing    int              `json:"numFollowing"`
	NumFollowers    int              `json:"numFollowers"`
	CurrentRoom     *Room            `json:"currentRoom"`
	BotOwnerId      NullString       `json:"botOwnerId"`
	FollowsYou      *bool            `json:"followsYou"`
	YouAreFollowing *bool            `json:"youAreFollowing"`
	IBlockedThem    *bool            `json:"iBlockedThem"`
	RoomPermissions *RoomPermissions `json:"roomPermissions"`
}

type ScheduledRoom

type ScheduledRoom struct {
	RoomId       UUID   `json:"roomId"`
	Description  string `json:"description"`
	ScheduledFor string `json:"scheduledFor"`
	NumAttending int    `json:"numAttending"`
	Name         string `json:"name"`
	Id           UUID   `json:"id"`
	CreatorId    UUID   `json:"creatorId"`
	Creator      User   `json:"creator"`
}

type SearchResult

type SearchResult struct {
	Items []interface{} `json:"items"`
	Rooms []Room        `json:"rooms"`
	Users []User        `json:"users"`
}

type Token

type Token string

type UUID

type UUID string

func (UUID) MarshalJSON

func (c UUID) MarshalJSON() ([]byte, error)

Make UUID and NullString types nullable

func (*UUID) UnmarshalJSON

func (c *UUID) UnmarshalJSON(in []byte) error

type User

type User struct {
	YouAreFollowing       bool                  `json:"youAreFollowing"`
	Username              string                `json:"username"`
	Online                bool                  `json:"online"`
	NumFollowing          int                   `json:"numFollowing"`
	NumFollowers          int                   `json:"numFollowers"`
	LastOnline            string                `json:"lastOnline"`
	Id                    UUID                  `json:"id"`
	FollowsYou            bool                  `json:"followsYou"`
	BotOwnerId            NullString            `json:"botOwnerId"`
	DisplayName           string                `json:"displayName"`
	CurrentRoomId         UUID                  `json:"currentRoomId"`
	CurrentRoom           Room                  `json:"currentRoom"`
	Bio                   NullString            `json:"bio"`
	AvatarUrl             string                `json:"avatarUrl"`
	BannerUrl             NullString            `json:"bannerUrl"`
	WhisperPrivacySetting WhisperPrivacySetting `json:"whisperPrivacySetting"`
}

type UserCreateBotResponse

type UserCreateBotResponse struct {
	ApiKey          *string `json:"apiKey"`
	IsUsernameToken *bool   `json:"isUsernameToken"`
	Error           *string `json:"error"`
}

type UserPreview

type UserPreview struct {
	Id           UUID       `json:"id"`
	DisplayName  string     `json:"displayName"`
	NumFollowers int        `json:"numFollowers"`
	AvatarUrl    NullString `json:"avatarUrl"`
}

type UserWithFollowInfo

type UserWithFollowInfo struct {
	Username        string     `json:"username"`
	Online          bool       `json:"online"`
	LastOnline      string     `json:"lastOnline"`
	Id              string     `json:"id"`
	Bio             string     `json:"bio"`
	DisplayName     string     `json:"displayName"`
	AvatarUrl       string     `json:"avatarUrl"`
	BannerUrl       string     `json:"bannerUrl"`
	NumFollowing    int        `json:"numFollowing"`
	NumFollowers    int        `json:"numFollowers"`
	CurrentRoom     *Room      `json:"currentRoom"`
	BotOwnerId      NullString `json:"botOwnerId"`
	FollowsYou      *bool      `json:"followsYou"`
	YouAreFollowing *bool      `json:"youAreFollowing"`
	IBlockedThem    *bool      `json:"iBlockedThem"`
}

type WhisperPrivacySetting

type WhisperPrivacySetting string

Jump to

Keyboard shortcuts

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