bot

package
v0.0.0-...-d3fc29d Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrefix        = "b!"
	DefaultMinDelay      = 120
	DefaultVariableDelay = 781
	DefaultStayTime      = 5 * time.Second
	HistoryDepth         = 10
)
View Source
const (
	FirstPageLabel    = "\u2060 \u2060 \u2060 First \u2060 \u2060 \u2060"
	PreviousPageLabel = "Previous"
	NextPageLabel     = "\u2060 \u2060 \u2060 Next \u2060 \u2060 \u2060"
	LastPageLabel     = "\u2060 \u2060 \u2060 Last \u2060 \u2060 \u2060"
)
View Source
const UnknownItem = "???"

Variables

View Source
var DefaultMemberPermissions int64 = DG.PermissionManageServer

Functions

func AddAdmin

func AddAdmin(b *Bot, p CommandParameters)

func AddChannel

func AddChannel(b *Bot, p CommandParameters)

func Admins

func Admins(b *Bot, p CommandParameters)

func Channels

func Channels(b *Bot, p CommandParameters)

func GiveNew

func GiveNew(b *Bot, p CommandParameters)

func Grab

func Grab(b *Bot, p CommandParameters)

func HandlerFromInteraction

func HandlerFromInteraction(b *Bot, cmd Command) func(*DG.Session, *DG.InteractionCreate)

func HandlerFromMessageCreate

func HandlerFromMessageCreate(b *Bot, cmd Command) func(*DG.Session, *DG.MessageCreate)

func Help

func Help(b *Bot, p CommandParameters)

func Info

func Info(b *Bot, p CommandParameters)

func IsHistoryInvalid

func IsHistoryInvalid(h History) bool

func PageReact

func PageReact(b *Bot) func(*DG.Session, *DG.InteractionCreate)

func Play

func Play(b *Bot, p CommandParameters)

func Prefix

func Prefix(b *Bot, p CommandParameters)

func RemoveAdmin

func RemoveAdmin(b *Bot, p CommandParameters)

func RemoveChannel

func RemoveChannel(b *Bot, p CommandParameters)

func Reset

func Reset(b *Bot, p CommandParameters)

func SendEmbed

func SendEmbed(s *DG.Session, i *DG.Interaction, channelID string, embed *DG.MessageEmbed, components []DG.MessageComponent) (*DG.Message, error)

func SendText

func SendText(s *DG.Session, i *DG.Interaction, channelID, content string) (*DG.Message, error)

func SetCooldown

func SetCooldown(b *Bot, p CommandParameters)

func SetPrefix

func SetPrefix(b *Bot, p CommandParameters)

func SetStay

func SetStay(b *Bot, p CommandParameters)

func ShowLeaderboard

func ShowLeaderboard(b *Bot, p CommandParameters)

func ShowScore

func ShowScore(b *Bot, p CommandParameters)

func Spawn

func Spawn(b *Bot, p CommandParameters)

Types

type Bot

type Bot struct {
	Log                 *LR.Logger
	UserID              string
	Mention             string
	Items               map[string]Item
	Monsters            map[string]Monster
	MonsterIds          []string
	Menus               map[string]Menu
	EqualMonsterChances bool
	InteractionHandlers InteractionHandlers
	Commands            []Command
	// contains filtered or unexported fields
}

func New

func New(log *LR.Logger) (*Bot, error)

func (*Bot) AddItems

func (b *Bot) AddItems(items []Item)

func (*Bot) Debug

func (b *Bot) Debug(format string, args ...interface{})

func (*Bot) DebugE

func (b *Bot) DebugE(err error, format string, args ...interface{})

func (*Bot) Error

func (b *Bot) Error(format string, args ...interface{})

func (*Bot) ErrorE

func (b *Bot) ErrorE(err error, format string, args ...interface{})

func (*Bot) Fatal

func (b *Bot) Fatal(format string, args ...interface{})

func (*Bot) FatalE

func (b *Bot) FatalE(err error, format string, args ...interface{})

func (*Bot) GetServer

func (b *Bot) GetServer(id string) Server

func (*Bot) GetUserScore

func (b *Bot) GetUserScore(user string, serv Server) int

func (*Bot) GetUserScoreboard

func (b *Bot) GetUserScoreboard(user string, serv Server) ScoreBoard

func (*Bot) Info

func (b *Bot) Info(format string, args ...interface{})

func (*Bot) NewServer

func (b *Bot) NewServer(id string) Server

func (*Bot) OpenDB

func (b *Bot) OpenDB()

func (*Bot) RandomMonster

func (b *Bot) RandomMonster() Monster

func (*Bot) SaveServer

func (b *Bot) SaveServer(s Server)

func (*Bot) SetupCommands

func (b *Bot) SetupCommands()

func (*Bot) SortedMonsters

func (b *Bot) SortedMonsters() (res []Monster)

func (*Bot) Stop

func (b *Bot) Stop()

func (*Bot) TotalPoints

func (b *Bot) TotalPoints() int

func (*Bot) TriggersAnyOtherCommand

func (b *Bot) TriggersAnyOtherCommand(p CommandParameters) bool

func (*Bot) Warn

func (b *Bot) Warn(format string, args ...interface{})

func (*Bot) WarnE

func (b *Bot) WarnE(err error, format string, args ...interface{})

type BotAction

type BotAction func(*Bot, CommandParameters)

type Command

type Command struct {
	Name   string
	Action BotAction

	Options        Options
	Admin          bool
	AlwaysTrigger  bool
	ModifiesServer bool
	// contains filtered or unexported fields
}

func (Command) DGOptions

func (c Command) DGOptions(b *Bot) []*DG.ApplicationCommandOption

func (Command) ID

func (c Command) ID() string

type CommandParameters

type CommandParameters struct {
	UID, CID, GID, Name string // MID only available on MessageCreate, else empty
	MsgCreate           *DG.MessageCreate
	I                   *DG.Interaction
	Options             map[string]interface{}
	S                   Server
	IsUserTriggered     bool
}

func ParamsFromInteraction

func ParamsFromInteraction(b *Bot, i *DG.InteractionCreate, name string) CommandParameters

func ParamsFromMessageCreate

func ParamsFromMessageCreate(b *Bot, m *DG.MessageCreate, name string) CommandParameters

func (*CommandParameters) ParseOptionsFromInteraction

func (p *CommandParameters) ParseOptionsFromInteraction(i *DG.Interaction, opts Options) error

func (*CommandParameters) ParseOptionsFromRaws

func (p *CommandParameters) ParseOptionsFromRaws(raws []string, opts Options) error

type Config

type Config struct {
	AppID             int       `json:"app-id" yaml:"app-id"`
	ClientID          int       `json:"client-id" yaml:"client-id"`
	PublicKey         string    `json:"public-key" yaml:"public-key"`
	ImgurClientID     string    `json:"imgur-client-id" yaml:"imgur-client-id"`
	ImgurClientSecret string    `json:"imgur-client-secret" yaml:"imgur-client-secret"`
	Token             string    `json:"token" yaml:"token"`
	Monsters          []Monster `json:"monsters" yaml:"monsters"`
	// contains filtered or unexported fields
}

func ReadConfig

func ReadConfig(log *LR.Logger) (Config, error)

type Game

type Game struct {
	On            bool
	Monsters      map[string]MonsterSpawn
	NextSpawn     time.Time
	MinDelay      time.Duration
	StayTime      time.Duration
	SpawnRate     int
	VariableDelay int
	Finished      bool
	LastMessages  History
	Winner        string
}

func (*Game) IncreaseSpawnRate

func (g *Game) IncreaseSpawnRate(rng U.RNG, msg *DG.Message)

func (*Game) ResetSpawnRate

func (g *Game) ResetSpawnRate()

func (*Game) Spawns

func (g *Game) Spawns(rng U.RNG) bool

type History

type History []Message

func NewHistory

func NewHistory() History

func (History) HasSeveralAuthors

func (h History) HasSeveralAuthors() bool

func (History) Span

func (h History) Span() time.Duration

func (History) String

func (h History) String() string

func (History) Update

func (h History) Update(msg *DG.Message) History

type InteractionHandlers

type InteractionHandlers map[string]func(*DG.Session, *DG.InteractionCreate)

type Item

type Item struct {
	ID     string  `json:"id,omitempty" yaml:"id,omitempty"`
	Name   string  `json:"name" yaml:"name"`
	Chance float64 `json:"chance" yaml:"chance"`
	Points int     `json:"points" yaml:"points"`
	Range  Range   `json:"range,omitempty" yaml:"range,omitempty"`
}

func (Item) Description

func (i Item) Description(hidden bool) string

type Leaderboard

type Leaderboard []ScoreBoard

func (Leaderboard) Strings

func (lb Leaderboard) Strings() []string

type Listable

type Listable interface {
	string
}
type Menu struct {
	L      []string // List to be displayed in a embed message
	Images []string // List of images to be set as thumbnails on each page
	// contains filtered or unexported fields
}

func NewMenu

func NewMenu(list []string, size int, cID, gID string) Menu
func (m *Menu) FirstPage(s *DG.Session)
func (m *Menu) GetComponents() []DG.MessageComponent
func (m *Menu) ID() string
func (m *Menu) LastPage(s *DG.Session)
func (m *Menu) NextPage(s *DG.Session)
func (m *Menu) PreviousPage(s *DG.Session)
func (m *Menu) Send(s *DG.Session, i *DG.Interaction) error
func (m *Menu) SetFooter(footer string)
func (m *Menu) SetHeader(header string)
func (m *Menu) SetImages(images []string)
func (m *Menu) SetSubtitle(subtitle string)
func (m *Menu) SetTitle(title string)

type Message

type Message struct {
	Time   time.Time
	Author string
	Valid  bool
}

func NewMessage

func NewMessage(author string, time time.Time) Message

type Monster

type Monster struct {
	ID               int     `json:"id" yaml:"id"`
	Name             string  `json:"name" yaml:"name"`
	Artist           string  `json:"artist" yaml:"artist"`
	Path             string  `json:"path" yaml:"path"`
	URL              string  `json:"url" yaml:"url"`
	Chance           float64 `json:"chance" yaml:"chance"`
	Items            []Item  `json:"items" yaml:"items"`
	Range            Range   `json:"range,omitempty" yaml:"range,omitempty"`
	EqualItemChances bool    `json:"equalchances,omitempty" yaml:"equalchances,omitempty"`
}

func (Monster) RandomItem

func (m Monster) RandomItem(rng U.RNG, log *LR.Logger) Item

type MonsterSpawn

type MonsterSpawn struct {
	ID       string
	Message  string
	Expected string
}

type Option

type Option struct {
	Name, Description string
	Type              OptionType
}

type OptionType

type OptionType string
const (
	TypeString  OptionType = "string"
	TypeInteger OptionType = "integer"
	TypeChannel OptionType = "channel"
	TypeUser    OptionType = "user"
)

type Options

type Options []Option

type Range

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

func (Range) Belongs

func (r Range) Belongs(n int) bool

type ScoreBoard

type ScoreBoard struct {
	UID   string
	Name  string
	Score int
	Rank  string
}

type Server

type Server struct {
	ID       string
	Prefix   string
	G        Game
	Channels []string
	Admins   []string
	Users    map[string][]string
	Lb       Leaderboard
}

func (Server) CanSpawn

func (s Server) CanSpawn(cid string) bool

CanSpawn returns true only if an item can spawn in the given channel

func (*Server) Cooldown

func (s *Server) Cooldown(rng U.RNG)

Cooldown sets the server game on cooldown

func (Server) IsAdmin

func (s Server) IsAdmin(uid string) bool

Jump to

Keyboard shortcuts

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