bot

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const AWS_SIZE_SOURCE = "https://www.ec2instances.info/"

list of Size slug, hourly cost

View Source
const DATA_SECURITY_NOTE = "(Note: All credentials are encrypted in transit and at rest)"
View Source
const DIGITALOCEAN_SIZE_SOURCE = "https://slugs.do-api.dev/"

list of Size slug, hourly cost

View Source
const ISSUE_LINK = "https://github.com/jack-michaud/ephemeral-server/issues/new"

Variables

View Source
var AWS_VALID_REGIONS = []string{
	"us-east-1",
	"us-west-2",
}
View Source
var AWS_VALID_SIZES = [][]string{
	{"t3a.nano", "$0.004700"},
	{"t3a.micro", "$0.009400"},
	{"t3a.small", "$0.018800"},
	{"t3a.medium", "$0.037600"},
	{"t3a.large", "$0.075200"},
	{"t3a.xlarge", "$0.150400"},
	{"t3a.2xlarge", "$0.300800"},
}
View Source
var DIGITALOCEAN_VALID_REGIONS = []string{
	"nyc1",
	"sfo1",
	"nyc2",
	"ams2",
	"sgp1",
	"lon1",
	"nyc3",
	"ams3",
	"fra1",
	"tor1",
	"sfo2",
	"blr1",
	"sfo3",
}
View Source
var DIGITALOCEAN_VALID_SIZES = [][]string{
	{"s-8vcpu-16gb", "$0.11905"},
	{"s-4vcpu-8gb", "$0.05952"},
	{"s-2vcpu-4gb", "$0.02976"},
	{"s-2vcpu-2gb", "$0.02232"},
	{"s-1vcpu-2gb", "$0.01488"},
	{"s-1vcpu-1gb", "$0.00744"},
}
View Source
var NilAction = func(s *discordgo.Session, m *discordgo.MessageCreate, config *Config, args []string) (error, *State) {
	return nil, nil
}
View Source
var SERVER_TYPES = []string{
	"vanilla-1.16.4",
	"skyfactory-4.2.2",
	"ftb-revelation-3.4.0",
}

Functions

func GetAuthorizedFilePublicKeyString

func GetAuthorizedFilePublicKeyString(pk *PrivateKey) ([]byte, error)

func GetPrivateKeyString

func GetPrivateKeyString(pk *PrivateKey) []byte

func GetSecretKey

func GetSecretKey() []byte

func InitializeBot

func InitializeBot(ctx context.Context, initializeConfig InitializeConfig) (*discordgo.Session, error)

func RunEphemeral

func RunEphemeral(ctx context.Context, kvConn store.IKVStore, action EphemeralAction, config *Config, textUpdateChannel chan string)

func SendError

func SendError(s *discordgo.Session, channelId string, err string)

Types

type Action

type Action = func(s *discordgo.Session, m *discordgo.MessageCreate, config *Config, args []string) (error, *State)

Returns an error and optionally a state that should be next.

type AwsCreds

type AwsCreds struct {
	AccessKeyId     string
	SecretAccessKey string
}

type Config

type Config struct {
	ServerId          string
	ServerIpAddress   *string
	CloudProvider     string
	DigitalOceanCreds *DigitalOceanCreds `json:",omitempty"`
	Region            string
	Size              string
	// Aws.
	AwsCreds *AwsCreds `json:",omitempty"`
	// Private key to access the VPS.
	PrivateKey     *PrivateKey `json:",omitempty"`
	ManagingRoleId string
	ServerType     string
}

func GetConfigForServerId

func GetConfigForServerId(Id string, conn store.IKVStore) (*Config, error)

Gets existing config from store or creates new config for server

func (*Config) HasBeenConfigured added in v1.3.1

func (c *Config) HasBeenConfigured() bool

func (*Config) SaveConfig

func (c *Config) SaveConfig(conn store.IKVStore) error

type ConfigMap

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

func NewConfigMap

func NewConfigMap() *ConfigMap

func (*ConfigMap) Get

func (cm *ConfigMap) Get(key string) (Config, bool)

func (*ConfigMap) Set

func (cm *ConfigMap) Set(key string, config Config)

type ConfigStateMachine

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

ConfigStateMachine stores the state of each guild ID. guildId -> State

func NewConfigStateMachine

func NewConfigStateMachine() *ConfigStateMachine

func (*ConfigStateMachine) Get

func (cm *ConfigStateMachine) Get(key string) (State, bool)

func (*ConfigStateMachine) Set

func (cm *ConfigStateMachine) Set(key string, state State)

type DigitalOceanCreds

type DigitalOceanCreds struct {
	AccessKey string
}

type EphemeralAction

type EphemeralAction int

Ephemeralctl actions

const (
	NO_OP EphemeralAction = iota
	DESTROY_ALL
	DESTROY_VPC
	// Idempotent
	CREATE
	GET_IP
	ANSIBLE_PROVISION
)

type InitializeConfig

type InitializeConfig struct {
	DiscordSecret string
	KVConn        store.IKVStore
}

type PrivateKey

type PrivateKey = rsa.PrivateKey

func GeneratePrivateKey

func GeneratePrivateKey() (*PrivateKey, error)

I'd like to use elliptic curve keys, but that's pending this issue: https://github.com/golang/go/issues/33564

type State

type State struct {
	Action Action
	// contains filtered or unexported fields
}

func InitializeConfigStateMachine

func InitializeConfigStateMachine(ctx context.Context, kvConn store.IKVStore) State

func NewState

func NewState(id string, action Action) State

Creates a new state (helper)

func (*State) AddState

func (s *State) AddState(pattern string, newState State)

Adds a given state to the list of possible next states.

func (*State) GetNextStateFromMessage

func (s *State) GetNextStateFromMessage(session *discordgo.Session, message *discordgo.MessageCreate, config *Config) State

Takes in a discord session, discord message, and server specific config.

Iterates through all possible next States on this state to see if there's a regex match in the message. If a message matches the next state, the next state's action is run. If the next state's action returns a new state, that state is returned. If there was an error from running the action, the initial state is returned. otherwise, the next state is returned.

Directories

Path Synopsis
cmd
run

Jump to

Keyboard shortcuts

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