bot

package
v0.0.0-...-bd02bc2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *db.DB
View Source
var DiscordCoreDataUpdated = sync.NewCond(new(sync.Mutex))
View Source
var ErrChannelNotFound = fmt.Errorf("Unable to find any channel by that name")
View Source
var ErrDiscordAPIUnresponsive = fmt.Errorf("The Discord api returned no data. Error assumed")

ErrSlackAPIUnresponsive means that on boot up we were unable to fetch any users from the slack api so we assume that the api is unresponsive. It needs to be there at least when starting up to get initial lists of users, groups, and channels

View Source
var ErrRoleNotFound = fmt.Errorf("Unable to find any role by that name")
View Source
var ErrUsernameNotFound = fmt.Errorf("Unable to find any user by that name")

ErrUsernameNotFound represents being unable to find a user by a given name (they can change)

View Source
var LogLevel = zap.InfoLevel

LogLevel sets the logging verbosity for the package

View Source
var Logger *zap.Logger
View Source
var StartupNotice = false

var Logger *zap.Logger

View Source
var UpdateRequest = make(chan struct{})
View Source
var UpdateTimer = 30 * time.Minute

UpdateTimer sets how often to check for updated users, group, and channel lists in slack

Functions

func GetMembers

func GetMembers() []*discordgo.Member

func IsUserIDAdmin

func IsUserIDAdmin(userID string) (bool, error)

IsUserIDAdmin checks the given Discord ID to check if the user has an admin role as defined in the bot package

func IsUserIDVerified

func IsUserIDVerified(userID string) (bool, error)

IsUserIDVerified checks if the Discord user with the id given has the verified role as defined in the bot package

func Member

func Member(id string) (*discordgo.Member, error)

Types

type Channel

type Channel struct {
	ID   string
	Name string
}

type ChannelCategory

type ChannelCategory struct {
	ID       string
	Name     string
	Channels []*Channel
}

type DiscordAPI

type DiscordAPI struct {
	Config DiscordCfg
	// contains filtered or unexported fields
}

func NewDiscordAPI

func NewDiscordAPI(cfg DiscordCfg, yt *youtube.Service) *DiscordAPI

func StartDiscord

func StartDiscord(cfg DiscordCfg, yt *youtube.Service) (*DiscordAPI, error)

StartDiscord starts Discord API bot

func (*DiscordAPI) Connect

func (d *DiscordAPI) Connect() error

Connect Needs to be called before any other API function work

func (*DiscordAPI) FindGuildRole

func (d *DiscordAPI) FindGuildRole(roleID string) (*discordgo.Role, error)

FindGuildRole searches the configured guild roles to find the one that matches the given roleID

func (*DiscordAPI) FindGuildRoleByName

func (d *DiscordAPI) FindGuildRoleByName(name string) (*discordgo.Role, error)

func (*DiscordAPI) FindIDByUsername

func (d *DiscordAPI) FindIDByUsername(username string) (string, string)

FindIDByUsername searches the server for a user with the specified username. Returns the ID and username

func (*DiscordAPI) FindIDByUsernameStartingAt

func (d *DiscordAPI) FindIDByUsernameStartingAt(username string, snowflake string) (string, string)

FindIDByUsernameStartingAt searches the server for a user with the specified username starting at the id/snowflake. Returns the ID and username

func (*DiscordAPI) MindGuild

func (d *DiscordAPI) MindGuild()

MindGuild starts routines to monitor Discord things like channels

func (*DiscordAPI) PostJoinEventMessage

func (d *DiscordAPI) PostJoinEventMessage(e *db.Event, member string) error

PostJoinEventMessage sends a new message to Discord when a user joins an event

func (*DiscordAPI) PostNewEventMessage

func (d *DiscordAPI) PostNewEventMessage(e *db.Event) error

PostNewEventMessage

func (DiscordAPI) PostStreamMessage

func (d DiscordAPI) PostStreamMessage(sm messaging.StreamMessage) error

func (*DiscordAPI) SendDM

func (d *DiscordAPI) SendDM(userID string, message string)

SendDM sends a DM to a user from the bot

func (*DiscordAPI) Shutdown

func (d *DiscordAPI) Shutdown()

Needs to be called to disconnect from discord

func (*DiscordAPI) StartRoleHandlers

func (d *DiscordAPI) StartRoleHandlers()

type DiscordCfg

type DiscordCfg struct {
	ClientId        string         `yaml:"appClientId"`
	Token           string         `yaml:"botToken"`
	StreamChannelId string         `yaml:"streamChannelId"`
	GuildId         string         `yaml:"guildId"`
	RoleCfg         DiscordRoleCfg `yaml:"roleConfig"`
}

type DiscordData

type DiscordData struct {
	sync.RWMutex
	Users             []*discordgo.Member
	Roles             []*discordgo.Role
	ChannelCategories []*discordgo.Channel
	Channels          []*discordgo.Channel
}

SlackData is the structure for the state that we are geeping "up to date" during runtime. It is ephemeral and goes away to be repopulated on program shutdown

func (*DiscordData) ChannelByID

func (d *DiscordData) ChannelByID(id string) (*discordgo.Channel, error)

func (*DiscordData) GetChannels

func (d *DiscordData) GetChannels() []*discordgo.Channel

GetChannels returns a list of all slack.Channels

func (*DiscordData) GetMembers

func (d *DiscordData) GetMembers() []*discordgo.Member

GetUsers returns a list of all slack.User

func (*DiscordData) IsUserIDAdmin

func (d *DiscordData) IsUserIDAdmin(id string) (bool, error)

func (*DiscordData) Member

func (d *DiscordData) Member(id string) (*discordgo.Member, error)

func (*DiscordData) MemberByNick

func (d *DiscordData) MemberByNick(username string) (*discordgo.Member, error)

UserByName is a helper function to find the slack.User for a given username (@{{username}})

func (*DiscordData) RoleByName

func (d *DiscordData) RoleByName(group string) (*discordgo.Role, error)

type DiscordEmojiRoleGroup

type DiscordEmojiRoleGroup struct {
	MessageTitle string      `yaml:"messageTitle"`
	MessageBody  string      `yaml:"messageBody"`
	Roles        []EmojiRole `yaml:"roles"`
}

type DiscordRoleCfg

type DiscordRoleCfg struct {
	ChannelId       string                  `yaml:"channelId"`
	EmojiRoleGroups []DiscordEmojiRoleGroup `yaml:"emojiRoles"`
}

type EmojiRole

type EmojiRole struct {
	EmojiId string `yaml:"emojiId"`
	RoleId  string `yaml:"roleId"`
}

type GuildChannels

type GuildChannels struct {
	Categories []ChannelCategory
}

Jump to

Keyboard shortcuts

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