entities

package
v1.2.0-Beta.2.0...-bcfade6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MongoLookupTimes = make(map[string]map[string][]ResponseTime)
	RedisLookupTimes = make(map[string]map[string][]ResponseTime)
	ResponseTimes    []ResponseTime
)
View Source
var (
	RatelimitedError = buildInternal(true, 429, "Too Many Requests", nil, nil, nil, nil)
	TempBannedError  = buildInternal(true, 403, "You've been temporarily API banned!", nil, nil, nil, nil)
	PermBannedError  = buildInternal(true, 403, "You've been permanently API banned!", nil, nil, nil, nil)
	NotFoundError    = buildInternal(true, 404, "Not Found", nil, nil, nil, nil)
	NoAuthError      = buildInternal(true, 403, `No "Authorization" header specified, or it was invalid!`, nil, nil, nil, nil)
	LookupError      = errors.New("an error occurred when looking up this resource")
	ReadFailed       = errors.New("failed to read request body")

	GetServersFailed   = buildInternal(true, 500, "An error occurred when getting all servers, try again later!", nil, nil, nil, nil)
	GetBotsFailed      = buildInternal(true, 500, "An error occurred when getting all bots, try again later!", nil, nil, nil, nil)
	GetUsersFailed     = buildInternal(true, 500, "An error occurred when getting all users, try again later!", nil, nil, nil, nil)
	GetTemplatesFailed = buildInternal(true, 500, "An error occurred when getting all templates, try again later!", nil, nil, nil, nil)
	BadContentType     = buildInternal(true, 415, "Unsupported Content Type, or non was provided!", nil, nil, nil, nil)
)

Functions

func AddMongoLookupTime

func AddMongoLookupTime(col, id string, lookup int64, unmarshal int64)

func AddRedisLookupTime

func AddRedisLookupTime(col, id string, lookup int64, unmarshal int64)

func BadAuth

func BadAuth(w http.ResponseWriter, _ *http.Request)

func NotFound

func NotFound(w http.ResponseWriter, _ *http.Request)

func PopulateDevCache

func PopulateDevCache()

func RequestLogger

func RequestLogger(handler http.Handler) http.Handler

func TokenValidator

func TokenValidator(next http.Handler) http.Handler

DELAPI_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-000000000000000000

func WriteBotResponse

func WriteBotResponse(w http.ResponseWriter, bot *Bot)

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, err error)

func WriteJson

func WriteJson(status int, writer http.ResponseWriter, v interface{})

func WriteNotImplementedResponse

func WriteNotImplementedResponse(w http.ResponseWriter)

func WritePrettyJson

func WritePrettyJson(status int, writer http.ResponseWriter, v interface{})

func WriteServerResponse

func WriteServerResponse(w http.ResponseWriter, server *Server)

func WriteTemplateResponse

func WriteTemplateResponse(w http.ResponseWriter, template *ServerTemplate)

func WriteUserResponse

func WriteUserResponse(w http.ResponseWriter, user *User)

Types

type APIHealthResponse

type APIHealthResponse struct {
	Error     bool  `json:"error"`
	Status    int   `json:"status"`
	RedisOK   bool  `json:"redis_ok"`
	MongoOK   bool  `json:"mongo_ok"`
	RedisPing int64 `json:"redis_ping"`
	MongoPing int64 `json:"mongo_ping"`
}

type APIResponse

type APIResponse struct {
	Error    bool            `json:"error"`
	Status   int             `json:"status"`
	Message  *string         `json:"message,omitempty"`
	Bot      *Bot            `json:"bot,omitempty"`
	Server   *Server         `json:"server,omitempty"`
	User     *User           `json:"user,omitempty"`
	Template *ServerTemplate `json:"template,omitempty"`
}

type APIResponseBots

type APIResponseBots struct {
	Error  bool  `json:"error"`
	Status int   `json:"status"`
	Bots   []Bot `json:"bots"`
}

type APIStatsResponse

type APIStatsResponse struct {
	Status    int                     `json:"status"`
	Error     bool                    `json:"error"`
	Servers   APIStatsResponseServers `json:"servers"`
	Bots      APIStatsResponseBots    `json:"bots"`
	Users     APIStatsResponseUsers   `json:"users"`
	Templates int                     `json:"templates"`
}

type APIStatsResponseBots

type APIStatsResponseBots struct {
	Total    int `json:"total"`
	Approved int `json:"approved"`
	Premium  int `json:"premium"`
}

type APIStatsResponseServers

type APIStatsResponseServers struct {
	Total int `json:"total"`
}

type APIStatsResponseStaff

type APIStatsResponseStaff struct {
	Total      int `json:"total"`
	Mods       int `json:"mods"`
	Assistants int `json:"assistants"`
	Admins     int `json:"admins"`
}

type APIStatsResponseUsers

type APIStatsResponseUsers struct {
	Total   int                   `json:"total"`
	Premium int                   `json:"premium"`
	Staff   APIStatsResponseStaff `json:"staff"`
}

type Avatar

type Avatar struct {
	Hash string `json:"hash"`
	URL  string `json:"url"`
}

type Bot

type Bot struct {
	MongoID     string     `json:"_id,omitempty"`
	ID          string     `bson:"_id" json:"id"`
	Name        string     `json:"name"`
	Prefix      string     `json:"prefix"`
	Library     string     `json:"library"`
	Tags        []string   `json:"tags"`
	VanityURL   string     `json:"vanityUrl"`
	ServerCount int        `json:"serverCount"`
	ShardCount  int        `json:"shardCount"`
	Token       string     `json:"token,omitempty"`
	Flags       int        `json:"flags"`
	ShortDesc   string     `json:"shortDesc"`
	LongDesc    string     `json:"longDesc"`
	ModNotes    string     `json:"modNotes,omitempty"`
	Editors     []string   `json:"editors"`
	Owner       Owner      `json:"owner"`
	Avatar      Avatar     `json:"avatar"`
	Votes       *BotVotes  `json:"votes,omitempty"`
	Links       BotLinks   `json:"links"`
	Social      BotSocial  `json:"social"`
	Theme       *BotTheme  `json:"theme,omitempty"`
	WidgetBot   *WidgetBot `json:"widgetbot,omitempty"`
	Status      BotStatus  `json:"status"`
}

func CleanupBot

func CleanupBot(rank UserRank, bot *Bot) *Bot

func GetAllBots

func GetAllBots(clean bool) (error, []Bot)

func LookupBot

func LookupBot(id string, clean bool) (error, *Bot)
type BotLinks struct {
	Invite        string `json:"invite"`
	Support       string `json:"support"`
	Website       string `json:"website"`
	Donation      string `json:"donation"`
	Repo          string `json:"repo"`
	PrivacyPolicy string `json:"privacyPolicy"`
}

type BotSocial

type BotSocial struct {
	Twitter string `json:"twitter"`
}

type BotStatus

type BotStatus struct {
	Approved bool `json:"approved"`
	Premium  bool `json:"premium,omitempty"`
	SiteBot  bool `json:"siteBot"`
	Archived bool `json:"archived"`
}

type BotTheme

type BotTheme struct {
	UseCustomColour bool   `json:"useCustomColour"`
	Colour          string `json:"colour"`
	Banner          string `json:"banner"`
}

type BotVotes

type BotVotes struct {
	Positive []string `json:"positive"`
	Negative []string `json:"negative"`
}

type DebugStatistics

type DebugStatistics struct {
	MongoPing     int64          `json:"mongo_ping"`
	RedisPing     int64          `json:"redis_ping"`
	Node          string         `json:"node"`
	LookupTimes   LookupTimes    `json:"lookup_times"`
	ResponseTimes []ResponseTime `json:"response_times"`
	Hostname      string         `json:"hostname"`
}

type GuildChannel

type GuildChannel struct {
	Type                  int                    `json:"type"`
	Position              int                    `json:"position,omitempty"`
	Name                  string                 `json:"name"`
	NSFW                  *bool                  `json:"nsfw,omitempty"`
	Topic                 *string                `json:"topic,omitempty"`
	PermissionsOverwrites []PermissionsOverwrite `json:"permissions_overwrites"`
	RateLimitPerUser      int                    `json:"rate_limit_per_user"`
	LastMessageID         string                 `json:"last_message_id"`
	Bitrate               *int                   `json:"bitrate,omitempty"`
	UserLimit             *int                   `json:"user_limit,omitempty"`
	LastPinTimestamp      *int                   `json:"last_pin_timestamp"`
}

type LookupTimes

type LookupTimes struct {
	Mongo map[string]map[string][]ResponseTime `json:"mongo"`
	Redis map[string]map[string][]ResponseTime `json:"redis"`
}

type Owner

type Owner struct {
	ID string `json:"id"`
}

type PermissionsOverwrite

type PermissionsOverwrite struct {
	ID    string `json:"id"`
	Type  string `json:"type"` // role/member
	Allow int    `json:"allow"`
	Deny  int    `json:"deny"`
}

type ResponseTime

type ResponseTime struct {
	Path                 string `json:"path,omitempty"`
	TimeTakenToLookup    int64  `json:"time_taken_to_lookup"`
	TimeSpentDecoding    int64  `json:"time_spent_decoding"`
	TimeSpentWritingBody int64  `json:"time_spent_writing_body"`
}

type Role

type Role struct {
	Name        string `json:"name"`
	Color       int    `json:"color"`
	Hoist       bool   `json:"hoist"`
	Position    int    `json:"position"`
	Permissions int    `json:"permissions"`
	Managed     bool   `json:"managed"`
	Mentionable bool   `json:"mentionable"`
}

type Server

type Server struct {
	MongoID        string       `json:"_id,omitempty"`
	ID             string       `bson:"_id" json:"id"`
	InviteCode     string       `json:"inviteCode,omitempty"`
	Name           string       `json:"name"`
	ShortDesc      string       `json:"shortDesc"`
	LongDesc       string       `json:"longDesc"`
	Tags           []string     `json:"tags"`
	PreviewChannel string       `json:"previewChannel"`
	Owner          Owner        `json:"owner"`
	Icon           Avatar       `json:"icon"`
	Links          ServerLinks  `json:"links"`
	Status         ServerStatus `json:"status"`
}

func CleanupServer

func CleanupServer(rank UserRank, server *Server) *Server

func GetAllServers

func GetAllServers(clean bool) (error, []Server)

func LookupServer

func LookupServer(id string, clean bool) (error, *Server)
type ServerLinks struct {
	Invite   string `json:"invite,omitempty"`
	Website  string `json:"website"`
	Donation string `json:"donation"`
}

type ServerStatus

type ServerStatus struct {
	ReviewRequired bool `json:"reviewRequired"`
}

type ServerTemplate

type ServerTemplate struct {
	MongoID                     string              `json:"_id,omitempty"`
	ID                          string              `bson:"_id" json:"id"`
	Name                        string              `json:"name"`
	Region                      string              `json:"region"`
	Locale                      string              `json:"locale"`
	AfkTimeout                  int                 `json:"afkTimeout"`
	VerificationLevel           int                 `json:"verificationLevel"`
	DefaultMessageNotifications int                 `json:"defaultMessageNotifications"`
	ExplicitContent             int                 `json:"explicitContent"`
	Roles                       []Role              `json:"roles"`
	Channels                    []GuildChannel      `json:"channels"`
	UsageCount                  int                 `json:"usageCount"`
	ShortDesc                   string              `json:"shortDesc"`
	LongDesc                    string              `json:"longDesc"`
	Tags                        []string            `json:"tags"`
	FromGuild                   string              `json:"fromGuild"`
	Owner                       Owner               `json:"owner"`
	Icon                        Avatar              `json:"icon"`
	Links                       ServerTemplateLinks `json:"links"`
}

func GetAllTemplates

func GetAllTemplates() (error, []ServerTemplate)

func LookupTemplate

func LookupTemplate(id string) (error, *ServerTemplate)
type ServerTemplateLinks struct {
	LinkToServerPage bool   `json:"linkToServerPage,omitempty"`
	Template         string `json:"template"`
}

type StaffTracking

type StaffTracking struct {
	Details struct {
		Away struct {
			Status  bool   `json:"status"`
			Message string `json:"message"`
		} `json:"away"`
		Standing        string `json:"standing"`
		Country         string `json:"country"`
		Timezone        string `json:"timezone"`
		ManagementNotes string `json:"managementNotes"`
	} `json:"details"`
	LastLogin    int `json:"lastLogin"`
	LastAccessed struct {
		Time int    `json:"time"`
		Page string `json:"page"`
	} `json:"lastAccessed"`
	Punishments struct {
		Strikes  []Strike `json:"strikes"`
		Warnings []Strike `json:"warnings"`
	} `json:"punishments"`
	HandledBots struct {
		AllTime  SubHandled `json:"allTime"`
		PrevWeek SubHandled `json:"prevWeek"`
		ThisWeek SubHandled `json:"thisWeek"`
	} `json:"handledBots"`
	HandledServers struct {
		AllTime  SubHandled `json:"allTime"`
		PrevWeek SubHandled `json:"prevWeek"`
		ThisWeek SubHandled `json:"thisWeek"`
	} `json:"handledServers"`
	HandledTemplates struct {
		AllTime  SubHandled `json:"allTime"`
		PrevWeek SubHandled `json:"prevWeek"`
		ThisWeek SubHandled `json:"thisWeek"`
	} `json:"handledTemplates"`
}

type Strike

type Strike struct {
	Reason   string `json:"reason"`
	Date     int    `json:"date"`
	Executor string `json:"executor"`
}

type SubHandled

type SubHandled struct {
	Total      int `json:"total"`
	Approved   int `json:"approved"`
	Declined   int `json:"declined"`
	Unapproved int `json:"unapproved"`
	Removed    int `json:"removed"`
}

type User

type User struct {
	MongoID       string           `json:"_id,omitempty"`
	ID            string           `bson:"_id" json:"id"`
	Token         string           `json:"token,omitempty"`
	Name          string           `json:"name"`
	Discrim       string           `json:"discrim"`
	FullUsername  string           `json:"fullUsername"`
	Locale        string           `json:"locale,omitempty"`
	Flags         int              `json:"flags"`
	Avatar        Avatar           `json:"avatar"`
	Preferences   *UserPreferences `json:"preferences,omitempty"`
	Profile       UserProfile      `json:"profile"`
	Game          UserGame         `json:"game"`
	Rank          UserRank         `json:"rank"`
	StaffTracking *StaffTracking   `json:"staffTracking,omitempty"`
}

func CleanupUser

func CleanupUser(rank UserRank, user *User) *User

func GetAllUsers

func GetAllUsers(clean bool) (error, []User)

func LookupUser

func LookupUser(id string, clean bool) (error, *User)

type UserGame

type UserGame struct {
	Snakes struct {
		MaxScore int `json:"maxScore"`
	} `json:"snakes"`
}

type UserPreferences

type UserPreferences struct {
	CustomGlobalCSS         string `json:"customGlobalCss"`
	DefaultColour           string `json:"defaultColour"`
	DefaultForegroundColour string `json:"defaultForegroundColour"`
	EnableGames             bool   `json:"enableGames"`
	Experiments             bool   `json:"experiments"`
}

type UserProfile

type UserProfile struct {
	Bio   string           `json:"bio"`
	CSS   string           `json:"css,omitempty"`
	Links UserProfileLinks `json:"links"`
}
type UserProfileLinks struct {
	Website   string `json:"website"`
	Github    string `json:"github"`
	Gitlab    string `json:"gitlab"`
	Twitter   string `json:"twitter"`
	Instagram string `json:"instagram"`
	Snapchat  string `json:"snapchat"`
}

type UserRank

type UserRank struct {
	Admin      bool `json:"admin"`
	Assistant  bool `json:"assistant"`
	Mod        bool `json:"mod"`
	Premium    bool `json:"premium,omitempty"`
	Tester     bool `json:"tester"`
	Translator bool `json:"translator"`
	Covid      bool `json:"covid"`
}

type WidgetBot

type WidgetBot struct {
	Channel string `json:"channel"`
	Options string `json:"options"`
	Server  string `json:"server"`
}

Jump to

Keyboard shortcuts

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