Skip to content

Commit

Permalink
v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Skye-31 authored Apr 13, 2021
2 parents 5ef37b6 + 10f129f commit 6189700
Show file tree
Hide file tree
Showing 136 changed files with 6,215 additions and 2,342 deletions.
86 changes: 43 additions & 43 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,56 @@
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '00 12 * * *'
push:
branches: [ master, development ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, development ]
schedule:
- cron: '0 0 1 * *'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2
steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Go

on:
push:
branches: [ master ]
branches: [ master, development ]
pull_request:
branches: [ master ]
branches: [ master, development ]

jobs:

Expand Down
4 changes: 2 additions & 2 deletions api/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package api

import "time"

// ActivityType represents the status of a user, one of Game, Streaming, Listening, Custom or Competing
// ActivityType represents the status of a user, one of Game, Streaming, Listening, Watching, Custom or Competing
type ActivityType int

// Constants for activities
const (
Game ActivityType = iota
Streaming
Listening
_
Watching
Custom
Competing
)
Expand Down
16 changes: 16 additions & 0 deletions api/audio_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package api

import "errors"

// errors returned when no gateway or ws conn exists
var (
ErrNoGateway = errors.New("no gateway initialized")
ErrNoGatewayConn = errors.New("no active gateway connection found")
)

// AudioController lets you Connect / Disconnect from a VoiceChannel
type AudioController interface {
Disgo() Disgo
Connect(guildID Snowflake, channelID Snowflake) error
Disconnect(guildID Snowflake) error
}
76 changes: 46 additions & 30 deletions api/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,77 @@ package api

// Cache allows you to access the objects that are stored in-memory by Discord
type Cache interface {
Disgo() Disgo
Close()
DoCleanup()
CacheFlags() CacheFlags

Guild(Snowflake) *Guild
GuildsByName(string, bool) []*Guild
Guilds() []*Guild
GuildCache() map[Snowflake]*Guild
CacheGuild(*Guild)
UncacheGuild(Snowflake)

/*Message(Snowflake) *Message
Messages(Snowflake) []*Message
AllMessages() []*Message
MessageCache(Snowflake) map[Snowflake]*Message
AllMessageCache() map[Snowflake]map[Snowflake]*Message
CacheMessage(*Message)
UncacheMessage(Snowflake)*/
Command(commandID Snowflake) *Command
GuildCommandCache(guildID Snowflake) map[Snowflake]*Command
AllGuildCommandCache() map[Snowflake]map[Snowflake]*Command
GlobalCommandCache() map[Snowflake]*Command
CacheGlobalCommand(command *Command) *Command
CacheGuildCommand(command *Command) *Command
UncacheCommand(commandID Snowflake)

User(Snowflake) *User
UserByTag(string) *User
UsersByName(string, bool) []*User
Users() []*User
UserCache() map[Snowflake]*User
CacheUser(*User)
CacheUser(*User) *User
UncacheUser(Snowflake)
FindUser(func(*User) bool) *User
FindUsers(func(*User) bool) []*User

Guild(Snowflake) *Guild
GuildsByName(string, bool) []*Guild
Guilds() []*Guild
GuildCache() map[Snowflake]*Guild
CacheGuild(*Guild) *Guild
UncacheGuild(Snowflake)

Message(channelID Snowflake, messageID Snowflake) *Message
Messages(channelID Snowflake) []*Message
MessageCache(channelID Snowflake) map[Snowflake]*Message
AllMessageCache() map[Snowflake]map[Snowflake]*Message
CacheMessage(message *Message) *Message
UncacheMessage(channelID Snowflake, messageID Snowflake)

Member(Snowflake, Snowflake) *Member
MemberByTag(Snowflake, string) *Member
MembersByName(Snowflake, string, bool) []*Member
Members(Snowflake) []*Member
AllMembers() []*Member
MemberCache(Snowflake) map[Snowflake]*Member
AllMemberCache() map[Snowflake]map[Snowflake]*Member
CacheMember(*Member)
CacheMember(member *Member) *Member
UncacheMember(Snowflake, Snowflake)
FindMember(Snowflake, func(*Member) bool) *Member
FindMembers(Snowflake, func(*Member) bool) []*Member

Role(Snowflake, Snowflake) *Role
VoiceState(guildID Snowflake, userID Snowflake) *VoiceState
VoiceStates(guildID Snowflake) []*VoiceState
VoiceStateCache(guildID Snowflake) map[Snowflake]*VoiceState
CacheVoiceState(voiceState *VoiceState) *VoiceState
UncacheVoiceState(guildID Snowflake, userID Snowflake)

Role(roleID Snowflake) *Role
RolesByName(Snowflake, string, bool) []*Role
Roles(Snowflake) []*Role
AllRoles() []*Role
RoleCache(Snowflake) map[Snowflake]*Role
AllRoleCache() map[Snowflake]map[Snowflake]*Role
CacheRole(*Role)
CacheRole(*Role) *Role
UncacheRole(Snowflake, Snowflake)
FindRole(Snowflake, func(*Role) bool) *Role
FindRoles(Snowflake, func(*Role) bool) []*Role

DMChannel(Snowflake) *DMChannel
DMChannels() []*DMChannel
DMChannelCache() map[Snowflake]*DMChannel
CacheDMChannel(*DMChannel)
UncacheDMChannel(Snowflake)
CacheDMChannel(*DMChannel) *DMChannel
UncacheDMChannel(dmChannelID Snowflake)
FindDMChannel(func(*DMChannel) bool) *DMChannel
FindDMChannels(func(*DMChannel) bool) []*DMChannel

Expand All @@ -69,7 +84,7 @@ type Cache interface {
TextChannelsByName(Snowflake, string, bool) []*TextChannel
TextChannels(Snowflake) []*TextChannel
TextChannelCache(Snowflake) map[Snowflake]*TextChannel
CacheTextChannel(*TextChannel)
CacheTextChannel(*TextChannel) *TextChannel
UncacheTextChannel(Snowflake, Snowflake)
FindTextChannel(Snowflake, func(*TextChannel) bool) *TextChannel
FindTextChannels(Snowflake, func(*TextChannel) bool) []*TextChannel
Expand All @@ -78,7 +93,7 @@ type Cache interface {
StoreChannelsByName(Snowflake, string, bool) []*StoreChannel
StoreChannels(Snowflake) []*StoreChannel
StoreChannelCache(Snowflake) map[Snowflake]*StoreChannel
CacheStoreChannel(*StoreChannel)
CacheStoreChannel(*StoreChannel) *StoreChannel
UncacheStoreChannel(Snowflake, Snowflake)
FindStoreChannel(Snowflake, func(*StoreChannel) bool) *StoreChannel
FindStoreChannels(Snowflake, func(*StoreChannel) bool) []*StoreChannel
Expand All @@ -87,7 +102,7 @@ type Cache interface {
VoiceChannelsByName(Snowflake, string, bool) []*VoiceChannel
VoiceChannels(Snowflake) []*VoiceChannel
VoiceChannelCache(Snowflake) map[Snowflake]*VoiceChannel
CacheVoiceChannel(*VoiceChannel)
CacheVoiceChannel(*VoiceChannel) *VoiceChannel
UncacheVoiceChannel(Snowflake, Snowflake)
FindVoiceChannel(Snowflake, func(*VoiceChannel) bool) *VoiceChannel
FindVoiceChannels(Snowflake, func(*VoiceChannel) bool) []*VoiceChannel
Expand All @@ -98,15 +113,16 @@ type Cache interface {
AllCategories() []*Category
CategoryCache(Snowflake) map[Snowflake]*Category
AllCategoryCache() map[Snowflake]map[Snowflake]*Category
CacheCategory(*Category)
CacheCategory(*Category) *Category
UncacheCategory(Snowflake, Snowflake)
FindCategory(Snowflake, func(*Category) bool) *Category
FindCategories(Snowflake, func(*Category) bool) []*Category

/*Emote(Snowflake) *Emote
EmotesByName(string, bool) []*Emote
Emotes() []*Emote
EmoteCache() map[Snowflake]*Emote
CacheEmote(*Emote)
UncacheEmote(Snowflake)*/
Emote(emoteID Snowflake) *Emote
EmotesByName(guildID Snowflake, name string, ignoreCase bool) []*Emote
Emotes(guildID Snowflake) []*Emote
EmoteCache(guildID Snowflake) map[Snowflake]*Emote
AllEmoteCache() map[Snowflake]map[Snowflake]*Emote
CacheEmote(*Emote) *Emote
UncacheEmote(guildID Snowflake, emoteID Snowflake)
}
77 changes: 77 additions & 0 deletions api/cache_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package api

// CacheFlags are used to enable/disable certain internal caches
type CacheFlags int

// values for CacheFlags
const (
CacheFlagsNone CacheFlags = 0
CacheFlagDMChannels CacheFlags = 1 << iota
CacheFlagCategories
CacheFlagTextChannels
CacheFlagVoiceChannels
CacheFlagStoreChannels
CacheFlagRoles
CacheFlagEmotes
CacheFlagVoiceState
CacheFlagCommands
CacheFlagCommandPermissions

CacheFlagsDefault = CacheFlagDMChannels |
CacheFlagCategories |
CacheFlagTextChannels |
CacheFlagVoiceChannels |
CacheFlagStoreChannels |
CacheFlagRoles |
CacheFlagEmotes
)

// Add allows you to add multiple bits together, producing a new bit
func (c CacheFlags) Add(bits ...Bit) Bit {
total := CacheFlags(0)
for _, bit := range bits {
total |= bit.(CacheFlags)
}
c |= total
return c
}

// Remove allows you to subtract multiple bits from the first, producing a new bit
func (c CacheFlags) Remove(bits ...Bit) Bit {
total := CacheFlags(0)
for _, bit := range bits {
total |= bit.(CacheFlags)
}
c &^= total
return c
}

// HasAll will ensure that the bit includes all of the bits entered
func (c CacheFlags) HasAll(bits ...Bit) bool {
for _, bit := range bits {
if !c.Has(bit) {
return false
}
}
return true
}

// Has will check whether the Bit contains another bit
func (c CacheFlags) Has(bit Bit) bool {
return (c & bit.(CacheFlags)) == bit
}

// MissingAny will check whether the bit is missing any one of the bits
func (c CacheFlags) MissingAny(bits ...Bit) bool {
for _, bit := range bits {
if !c.Has(bit) {
return true
}
}
return false
}

// Missing will do the inverse of Bit.Has
func (c CacheFlags) Missing(bit Bit) bool {
return !c.Has(bit)
}
Loading

0 comments on commit 6189700

Please sign in to comment.