cardsagainstdiscord

package
v2.47.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 14 Imported by: 0

README

cards against discord

A discord bot for cards against humanity, and unlike other cah bots, you dont type your shit, you use the power of reactions to pick your shizz, MAGIC.

Pretty functional, some bugs may be around.

To compile and run the standalone bot: (assuming you have go and git installed)

go get github.com/jonas747/cardsagainstdiscord/cmd/cardsagainstdiscord
cd $GOPATH/bin
# The executable now lies here, set DG_TOKEN to your token prefixed with "Bot " and run it

Documentation

Index

Constants

View Source
const (
	PreRoundDelayDuration  = time.Second * 15
	PickResponseDuration   = time.Second * 60
	PickWinnerDuration     = time.Second * 90
	GameExpireAfter        = time.Second * 300
	GameExpireAfterPregame = time.Minute * 30

	BlankCard ResponseCard = "(write your own response)"
)

Variables

View Source
var (
	ErrGameAlreadyInChannel = errors.New("Already a active game in this channel")
	ErrPlayerAlreadyInGame  = errors.New("Player already in a game")
	ErrGameNotFound         = errors.New("Game not found")
	ErrGameFull             = errors.New("Game is full")
	ErrNoPacks              = errors.New("No packs specified")
	ErrNotGM                = errors.New("You're not the game master")
	ErrStoppedAlready       = errors.New("Game already stopped")
	ErrPlayerNotInGame      = errors.New("Player not in your game")
	ErrAllPacksResponseOnly = errors.New("The set of packs specified are all response-only; at least one pack that has prompts is needed to start a game")
)
View Source
var (
	CardSelectionEmojis = []string{
		"🇦",
		"🇧",
		"🇨",
		"🇩",
		"🇪",
		"🇫",
		"🇬",
		"🇭",
		"🇮",
		"🇯",
		"🇰",
	}

	JoinEmoji      = "➕"
	LeaveEmoji     = "➖"
	PlayPauseEmoji = "⏯"

	CahGameJoined    = "cah_game_joined"
	CahGameLeft      = "cah_game_left"
	CahGamePlayPause = "cah_game_play"

	CahCardSelectMenu = "cah_card_select"
	CahBlankCardModal = "cah_blank_card"
	CahTextInput      = "cah_text_input"
)
View Source
var (
	EscaperReplacer = strings.NewReplacer("*", "\\*", "_", "\\_")
)
View Source
var Packs = make(map[string]*CardPack)

Functions

func AddPack

func AddPack(pack *CardPack)

func FilterEveryoneMentions

func FilterEveryoneMentions(s string) string

func GetCommonCahButtons added in v2.7.0

func GetCommonCahButtons() []discordgo.MessageComponent

func HumanizeError

func HumanizeError(err error) string

func NextCardCzar

func NextCardCzar(players []*Player, current int64) int64

Types

type CardPack

type CardPack struct {
	Name        string
	Description string
	Prompts     []*PromptCard
	Responses   []ResponseCard
}

type ErrUnknownPack

type ErrUnknownPack struct {
	PassedPack  string
	Suggestions []string
}

func (*ErrUnknownPack) Error

func (e *ErrUnknownPack) Error() string

type Game

type Game struct {
	sync.RWMutex `json:"-" msgpack:"-"`
	// Never chaged
	Manager *GameManager       `json:"-" msgpack:"-"`
	Session *discordgo.Session `json:"-" msgpack:"-"`

	// The main channel this game resides in, never changes
	MasterChannel int64
	// The server the game resides in, never changes
	GuildID int64

	// The user that created this game
	GameMaster int64

	// The current cardzar
	CurrentCardCzar int64

	PlayerLimit int
	WinLimit    int
	VoteMode    bool
	Packs       []string

	Players []*Player

	State        GameState
	StateEntered time.Time

	// The time the most recent action was taken, if we go too long without a user action we expire the game
	LastAction time.Time

	CurrentPropmpt *PromptCard

	LastMenuMessage int64

	Responses []*PickedResonse
	// contains filtered or unexported fields
}

func (*Game) AddPlayer

func (g *Game) AddPlayer(id int64, username string) bool

AddPlayer attempts to add a player to the game, if it fails (hit the limit for example) then it returns false

func (*Game) Created

func (g *Game) Created() error

func (*Game) HandleInteractionAdd added in v2.7.0

func (g *Game) HandleInteractionAdd(ic *discordgo.InteractionCreate)

func (*Game) HandleMessageCreate

func (g *Game) HandleMessageCreate(ic *discordgo.InteractionCreate)

func (*Game) RemovePlayer

func (g *Game) RemovePlayer(id int64) bool

func (*Game) Stop

func (g *Game) Stop()

func (*Game) Tick

func (g *Game) Tick()

type GameManager

type GameManager struct {
	sync.RWMutex
	SessionProvider SessionProvider
	ActiveGames     map[int64]*Game
	NumActiveGames  int
}

func NewGameManager

func NewGameManager(sessionProvider SessionProvider) *GameManager

func (*GameManager) AdminKickUser

func (gm *GameManager) AdminKickUser(admin, playerID int64) error

func (*GameManager) CreateGame

func (gm *GameManager) CreateGame(guildID int64, channelID int64, userID int64, username string, voteMode bool, packs ...string) (*Game, error)

func (*GameManager) FindGameFromChannelOrUser

func (gm *GameManager) FindGameFromChannelOrUser(id int64) *Game

func (*GameManager) HandleCahInteraction added in v2.7.0

func (gm *GameManager) HandleCahInteraction(ic *discordgo.InteractionCreate)

func (*GameManager) HandleInteractionCreate added in v2.7.0

func (gm *GameManager) HandleInteractionCreate(ic *discordgo.InteractionCreate)

func (*GameManager) LoadGameFromSerializedState

func (gm *GameManager) LoadGameFromSerializedState(game *Game)

func (*GameManager) PlayerTryJoinGame

func (gm *GameManager) PlayerTryJoinGame(gameID, playerID int64, username string) error

func (*GameManager) PlayerTryLeaveGame

func (gm *GameManager) PlayerTryLeaveGame(playerID int64) error

func (*GameManager) RemoveGame

func (gm *GameManager) RemoveGame(gameID int64) error

func (*GameManager) TryAdminRemoveGame

func (gm *GameManager) TryAdminRemoveGame(admin int64) error

type GameState

type GameState int
const (
	GameStatePreGame          GameState = 0 // Before the game starts
	GameStatePreRoundDelay    GameState = 1 // Countdown before a round starts
	GameStatePickingResponses GameState = 2 // Players are picking responses for the prompt card
	GameStatePickingWinner    GameState = 3 // Cardzar is picking the winning response
	GameStateEnded            GameState = 4 // Game is over, someone won
)

type PickedResonse

type PickedResonse struct {
	Player     *Player
	Selections []ResponseCard
}

type Player

type Player struct {
	ID              int64
	Username        string
	Cards           []ResponseCard
	SelectedCards   []int
	Wins            int
	FilingBlankCard bool
	VotedFor        int64
	ReceivedVotes   int

	Channel int64

	// Wether this user is playing this round, if the user joined in the middle of a round this will be false
	Playing bool
	InGame  bool
	Banned  bool

	LastReactionMenu int64
	// contains filtered or unexported fields
}

func (*Player) MadeSelections

func (p *Player) MadeSelections(currentPrompt *PromptCard) bool

func (*Player) PlayingThisRound

func (p *Player) PlayingThisRound() bool

func (*Player) PresentBoard

func (p *Player) PresentBoard(session *discordgo.Session, currentPrompt *PromptCard, currentCardCzar int64)

type PromptCard

type PromptCard struct {
	Prompt  string
	NumPick int
}

func (*PromptCard) PlaceHolder

func (p *PromptCard) PlaceHolder() string

func (*PromptCard) WithCards

func (p *PromptCard) WithCards(cards interface{}) string

type ResponseCard

type ResponseCard string

type SessionProvider

type SessionProvider interface {
	SessionForGuild(guildID int64) *discordgo.Session
}

type StaticSessionProvider

type StaticSessionProvider struct {
	Session *discordgo.Session
}

func (*StaticSessionProvider) SessionForGuild

func (sp *StaticSessionProvider) SessionForGuild(guildID int64) *discordgo.Session

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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