events

package
v0.0.0-...-ab145b9 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 42 Imported by: 49

Documentation

Index

Constants

View Source
const (
	NoStorageSpace          string = "common.noStorageSpace"
	NoStoragePermission     string = "common.noStoragePermission"
	FileTooBig              string = "common.fileTooBig"
	CouldNotExtractFilename string = "common.couldNotExtractFilename"
)

Variables

View Source
var (
	SpanLabelEventingType      = label.Key("eventing_type")
	SpanLabelEventingIsCommand = label.Key("eventing_is_command")
	SpanLabelEventingCommand   = label.Key("eventing_command")
	SpanLabelDiscordBotUserID  = label.Key("discord_bot_user_id")
	SpanLabelDiscordGuildID    = label.Key("discord_guild_id")
	SpanLabelDiscordChannelID  = label.Key("discord_channel_id")
	SpanLabelDiscordUserID     = label.Key("discord_user_id")
	SpanLabelDiscordMessageID  = label.Key("discord_message_id")
)

Functions

func InitObjectStorage

func InitObjectStorage(db *gorm.DB, fqdn string, bucketName string) error

func WithoutFallbackToSelf

func WithoutFallbackToSelf() optionFunc

nolint: golint

Types

type AutomodWait

type AutomodWait struct {
	EnvData []byte
}

type BucketType

type BucketType string

BucketType specifies the scope of a bucket

const (
	GuildBucketType   BucketType = "guild_bucket"
	ChannelBucketType BucketType = "channel_bucket"
	UserBucketType    BucketType = "user_bucket"
)

defines various bucket scopes

type BucketUpdate

type BucketUpdate struct {
	Type      BucketType
	Tag       string
	GuildID   string
	KeySuffix string
	EnvDatas  [][]byte
}

type Consumer

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

Consumer processes incoming events

func NewConsumer

func NewConsumer(
	logger *zap.Logger,
	serviceName string,
	amqpDSN string,
	concurrentProcessingLimit int,
	handler func(*Event) error,
) (*Consumer, error)

NewConsumer creates a new processor

func (*Consumer) Start

func (c *Consumer) Start(ctx context.Context) error

Start starts processing events

type DiffChannel

type DiffChannel struct {
	Old *discordgo.Channel `json:"old"`
	New *discordgo.Channel `json:"new"`
}

type DiffEmoji

type DiffEmoji struct {
	Old []*discordgo.Emoji `json:"old"`
	New []*discordgo.Emoji `json:"new"`
}

type DiffGuild

type DiffGuild struct {
	Old *discordgo.Guild `json:"old"`
	New *discordgo.Guild `json:"new"`
}

type DiffInvites

type DiffInvites struct {
	Old []*discordgo.Invite `json:"old"`
	New []*discordgo.Invite `json:"new"`
}

type DiffMember

type DiffMember struct {
	Old *discordgo.Member `json:"old"`
	New *discordgo.Member `json:"new"`
}

type DiffRole

type DiffRole struct {
	Old *discordgo.Role `json:"old"`
	New *discordgo.Role `json:"new"`
}

type DiffWebhooks

type DiffWebhooks struct {
	Old []*discordgo.Webhook `json:"old"`
	New []*discordgo.Webhook `json:"new"`
}

type Event

type Event struct {
	ID          string      `json:"id"`
	CacheKey    string      `json:"cache_key"`
	Type        Type        `json:"type"`
	ReceivedAt  time.Time   `json:"received_at" dynamodbav:"received_at,unixtime"`
	BotUserID   string      `json:"bot_user_id"`
	GuildID     string      `json:"guild_id,omitempty"`
	ChannelID   string      `json:"channel_id,omitempty"`
	UserID      string      `json:"user_id,omitempty"`
	MessageID   string      `json:"message_id,omitempty"`
	SuperUser   bool        `json:"super_user"`
	SpanContext SpanContext `json:"span_context"`

	// discordgo event data
	ChannelCreate     *discordgo.ChannelCreate     `json:"discord_channel_create,omitempty"`
	ChannelDelete     *discordgo.ChannelDelete     `json:"discord_channel_delete,omitempty"`
	ChannelPinsUpdate *discordgo.ChannelPinsUpdate `json:"discord_channel_pins_update,omitempty"`
	ChannelUpdate     *discordgo.ChannelUpdate     `json:"discord_channel_update,omitempty"`
	GuildBanAdd       *discordgo.GuildBanAdd       `json:"discord_guild_ban_add,omitempty"`
	GuildBanRemove    *discordgo.GuildBanRemove    `json:"discord_guild_ban_remove,omitempty"`
	GuildCreate       *discordgo.GuildCreate       `json:"discord_guild_create,omitempty"`
	GuildDelete       *discordgo.GuildDelete       `json:"discord_guild_delete,omitempty"`
	GuildEmojisUpdate *discordgo.GuildEmojisUpdate `json:"discord_guild_emojis_update,omitempty"`
	GuildMemberAdd    *discordgo.GuildMemberAdd    `json:"discord_guild_member_add,omitempty"`
	// GuildMemberAddExtra      *GuildMemberAddExtra                `json:"cacophony_guild_member_add_extra,omitempty"`
	GuildMemberRemove        *discordgo.GuildMemberRemove        `json:"discord_guild_member_remove,omitempty"`
	GuildMemberUpdate        *discordgo.GuildMemberUpdate        `json:"discord_guild_member_update,omitempty"`
	GuildMembersChunk        *discordgo.GuildMembersChunk        `json:"discord_guild_members_chunk,omitempty"`
	GuildRoleCreate          *discordgo.GuildRoleCreate          `json:"discord_guild_role_create,omitempty"`
	GuildRoleDelete          *discordgo.GuildRoleDelete          `json:"discord_guild_role_delete,omitempty"`
	GuildRoleUpdate          *discordgo.GuildRoleUpdate          `json:"discord_guild_role_update,omitempty"`
	GuildUpdate              *discordgo.GuildUpdate              `json:"discord_guild_update,omitempty"`
	MessageCreate            *discordgo.MessageCreate            `json:"discord_message_create,omitempty"`
	MessageDelete            *discordgo.MessageDelete            `json:"discord_message_delete,omitempty"`
	MessageReactionAdd       *discordgo.MessageReactionAdd       `json:"discord_message_reaction_add,omitempty"`
	MessageReactionRemove    *discordgo.MessageReactionRemove    `json:"discord_message_reaction_remove,omitempty"`
	MessageReactionRemoveAll *discordgo.MessageReactionRemoveAll `json:"discord_message_reaction_remove_all,omitempty"`
	MessageUpdate            *discordgo.MessageUpdate            `json:"discord_message_update,omitempty"`
	PresenceUpdate           *discordgo.PresenceUpdate           `json:"discord_presence_update,omitempty"`
	GuildIntegrationsUpdate  *discordgo.GuildIntegrationsUpdate  `json:"discord_guild_integrations_update,omitempty"`
	MessageDeleteBulk        *discordgo.MessageDeleteBulk        `json:"discord_message_delete_bulk,omitempty"`
	UserUpdate               *discordgo.UserUpdate               `json:"discord_user_update,omitempty"`
	VoiceStateUpdate         *discordgo.VoiceStateUpdate         `json:"discord_voice_state_update,omitempty"`
	VoiceServerUpdate        *discordgo.VoiceServerUpdate        `json:"discord_voice_server_update,omitempty"`
	WebhooksUpdate           *discordgo.WebhooksUpdate           `json:"discord_webhooks_update,omitempty"`
	InteractionCreate        *discordgo.InteractionCreate        `json:"discord_interaction_create,omitempty"`

	// Cacophony Event Data
	BucketUpdate           *BucketUpdate           `json:"cacophony_bucket_update,omitempty"`
	ServerlistServerExpire *ServerlistServerExpire `json:"cacophony_serverlist_server_expire,omitempty"`
	QuickactionRemind      *QuickactionRemind      `json:"cacophony_quickaction_remind,omitempty"`
	QuestionnaireMatch     *QuestionnaireMatch     `json:"cacophony_questionnaire_match,omitempty"`
	AutomodWait            *AutomodWait            `json:"cacophony_automod_wait,omitempty"`
	EventlogUpdate         *EventlogUpdate         `json:"cacophony_eventlog_update,omitempty"`
	DiffGuild              *DiffGuild              `json:"cacophony_diff_guild,omitempty"`
	DiffMember             *DiffMember             `json:"cacophony_diff_member,omitempty"`
	DiffChannel            *DiffChannel            `json:"cacophony_diff_channel,omitempty"`
	DiffRole               *DiffRole               `json:"cacophony_diff_role,omitempty"`
	DiffEmoji              *DiffEmoji              `json:"cacophony_diff_emoji,omitempty"`
	DiffWebhooks           *DiffWebhooks           `json:"cacophony_diff_webhooks,omitempty"`
	DiffInvites            *DiffInvites            `json:"cacophony_diff_invites,omitempty"`
	// contains filtered or unexported fields
}

Event represents an Event nolint: maligned

func GenerateEventFromDiscordgoEvent

func GenerateEventFromDiscordgoEvent(
	botUserID string, eventItem interface{},
) (
	*Event, time.Duration, error,
)

GenerateEventFromDiscordgoEvent generates an Event from a Discordgo Event

func New

func New(eventType Type) (*Event, error)

func (*Event) AddAttachement

func (e *Event) AddAttachement(attachement *discordgo.MessageAttachment) (*FileInfo, error)

func (*Event) AddFile

func (e *Event) AddFile(data []byte, file *FileInfo) (*FileInfo, error)

func (*Event) AddFileFromURL

func (e *Event) AddFileFromURL(link string, filename string) (*FileInfo, error)

func (*Event) BotMention

func (e *Event) BotMention() bool

Command returns true if the event is a @Bot

func (*Event) Command

func (e *Event) Command() bool

Command returns true if the event is a command message

func (*Event) Context

func (e *Event) Context() context.Context

Context returns the context for the event

func (*Event) DB

func (e *Event) DB() *gorm.DB

DB retrieves the DB Client from the event

func (*Event) DM

func (e *Event) DM() bool

DM returns true if the event is a DM message

func (*Event) DeleteFile

func (e *Event) DeleteFile(file *FileInfo) error

func (*Event) Discord

func (e *Event) Discord() *discord.Session

Discord gets the Discord API client for the events bot

func (*Event) Except

func (e *Event) Except(err error, fields ...string)

func (*Event) ExceptSilent

func (e *Event) ExceptSilent(err error, fields ...string)

func (*Event) FeatureFlagger

func (e *Event) FeatureFlagger() *featureflag.FeatureFlagger

func (*Event) Fields

func (e *Event) Fields() []string

Fields returns all fields of a command, includes the command

func (*Event) FieldsVariadic

func (e *Event) FieldsVariadic(start int) string

FieldsVariadic gives a string of all fields starting a given position, eg `_test foo bar baz qux quux` => `e.FieldsVariadic(2) => `"bar baz qux quux"`

func (*Event) FindAnyChannel

func (e *Event) FindAnyChannel(opts ...optionFunc) (*discordgo.Channel, error)

FindAnyChannel finds any kind of target channel in the command channels have to be on the current guild

func (*Event) FindChannel

func (e *Event) FindChannel(opts ...optionFunc) (*discordgo.Channel, error)

FindChannel finds a target text channel in the command channels have to be on the current guild

func (*Event) FindMember

func (e *Event) FindMember(opts ...optionFunc) (*discordgo.User, error)

FindMember finds any kind of member in the command

func (e *Event) FindMessageLink(link string) (*discordgo.Message, error)

func (*Event) FindRole

func (e *Event) FindRole(opts ...optionFunc) (*discordgo.Role, error)

FindRole finds a target role in the command the role has to be on the current guild

func (*Event) FindUser

func (e *Event) FindUser(opts ...optionFunc) (*discordgo.User, error)

FindUser finds any kind of target user in the command

func (*Event) GetUserStorageUsage

func (e *Event) GetUserStorageUsage() (*UserStorageInfo, error)

func (*Event) HTTPClient

func (e *Event) HTTPClient() *http.Client

func (*Event) Has

func (e *Event) Has(
	firstPermission interfaces.Permission,
	permissions ...interfaces.Permission,
) bool

Has returns true if the user has all the required permissions

func (*Event) HasOr

func (e *Event) HasOr(
	firstPermission interfaces.Permission,
	permissions ...interfaces.Permission,
) bool

HasOr returns true if the user has one of the required permissions

func (*Event) IsEnabled

func (e *Event) IsEnabled(key string, fallback bool) bool

func (*Event) Localizations

func (e *Event) Localizations() []interfaces.Localization

Localizations retrieves the localizations from the event

func (*Event) Logger

func (e *Event) Logger() *zap.Logger

Logger retrieves the logger from the event

func (*Event) OriginalCommand

func (e *Event) OriginalCommand() string

OriginalCommand returns the first command without any modifications to casing

mainly used for custom commands module

func (*Event) Paginator

func (e *Event) Paginator() *paginator.Paginator

Paginator retrieves the Paginator from the event

func (*Event) Parse

func (e *Event) Parse()

Parse parses the content of a message into fields

func (*Event) Prefix

func (e *Event) Prefix() string

Prefix returns the prefix of a command, if event is a command

func (*Event) Publisher

func (e *Event) Publisher() *Publisher

func (*Event) Questionnaire

func (e *Event) Questionnaire() *Questionnaire

func (*Event) React

func (e *Event) React(emojiID string, emojiIDs ...string) error

func (*Event) Redis

func (e *Event) Redis() *redis.Client

Redis retrieves the Redis Client from the event

func (*Event) Require

func (e *Event) Require(
	callback func(),
	firstPermission interfaces.Permission,
	permissions ...interfaces.Permission,
)

Require calls the callback if the user has all of the required permissions

func (*Event) RequireOr

func (e *Event) RequireOr(
	callback func(),
	firstPermission interfaces.Permission,
	permissions ...interfaces.Permission,
)

RequireOr calls the callback if the user has one of the required permissions

func (*Event) Respond

func (e *Event) Respond(message string, values ...interface{}) ([]*discordgo.Message, error)

Respond sends a message to the source channel, translates it if possible

func (*Event) RespondComplex

func (e *Event) RespondComplex(message *discordgo.MessageSend, values ...interface{}) ([]*discordgo.Message, error)

RespondComplex sends a message to the source channel, translates it if possible

func (*Event) RespondDM

func (e *Event) RespondDM(message string, values ...interface{}) ([]*discordgo.Message, error)

func (*Event) Send

func (e *Event) Send(channelID, message string, values ...interface{}) ([]*discordgo.Message, error)

Send sends a message to the given channel, translates it if possible TODO: check language

func (*Event) SendComplex

func (e *Event) SendComplex(channelID string, message *discordgo.MessageSend, values ...interface{}) ([]*discordgo.Message, error)

SendComplex sends a message to the given channel, translates it if possible TODO: check language

func (*Event) SendComplexDM

func (e *Event) SendComplexDM(userID string, message *discordgo.MessageSend, values ...interface{}) ([]*discordgo.Message, error)

func (*Event) SendDM

func (e *Event) SendDM(userID, message string, values ...interface{}) ([]*discordgo.Message, error)

func (*Event) SetTimezone

func (e *Event) SetTimezone(timezone *time.Location) error

func (*Event) State

func (e *Event) State() *state.State

State retrieves the state from the event

func (*Event) Storage

func (e *Event) Storage() *Storage

func (*Event) Timezone

func (e *Event) Timezone() *time.Location

func (*Event) Translate

func (e *Event) Translate(key string, values ...interface{}) string

Translate translates a given key for the event

func (*Event) Typing

func (e *Event) Typing()

Typing starts typing in the event channel

func (*Event) UpdateFileInfo

func (e *Event) UpdateFileInfo(file FileInfo) error

func (*Event) WithContext

func (e *Event) WithContext(ctx context.Context)

WithContext sets the context for the event

func (*Event) WithDB

func (e *Event) WithDB(db *gorm.DB)

WithDB stores the DB Client in the event

func (*Event) WithFeatureFlagger

func (e *Event) WithFeatureFlagger(featureFlagger *featureflag.FeatureFlagger)

func (*Event) WithHTTPClient

func (e *Event) WithHTTPClient(client *http.Client)

func (*Event) WithLocalizations

func (e *Event) WithLocalizations(localizations []interfaces.Localization)

WithLocalizations stores the localizations in the event

func (*Event) WithLogger

func (e *Event) WithLogger(logger *zap.Logger)

WithLogger stores a logger in the event

func (*Event) WithPaginator

func (e *Event) WithPaginator(paginator *paginator.Paginator)

WithPaginator stores the Paginator in the event

func (*Event) WithPublisher

func (e *Event) WithPublisher(publisher *Publisher)

func (*Event) WithQuestionnaire

func (e *Event) WithQuestionnaire(questionnaire *Questionnaire)

func (*Event) WithRedis

func (e *Event) WithRedis(redisClient *redis.Client)

WithRedis stores the Redis Client in the event

func (*Event) WithState

func (e *Event) WithState(state *state.State)

WithState stores the state in the event

func (*Event) WithStorage

func (e *Event) WithStorage(storage *Storage)

WithStorage stores the storage bucket in the event

func (*Event) WithTokens

func (e *Event) WithTokens(tokens map[string]string)

type EventlogUpdate

type EventlogUpdate struct {
	GuildID string
	ItemID  uint
}

type FileInfo

type FileInfo struct {
	gorm.Model

	Filename        string
	UserID          string
	ChannelID       string
	GuildID         string
	FileID          string
	Source          string
	MimeType        string
	UploadDate      time.Time
	Filesize        int
	RetrievedCount  int
	Public          bool
	CustomCommandID uint
}
func (f *FileInfo) GetLink() string

func (*FileInfo) TableName

func (f *FileInfo) TableName() string

type Publisher

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

func NewPublisher

func NewPublisher(
	amqpDSN string,
	db *gorm.DB,
) (*Publisher, error)

func (*Publisher) Publish

func (p *Publisher) Publish(
	ctx context.Context,
	event *Event,
) (err error, recoverable bool)

func (*Publisher) PublishAt

func (p *Publisher) PublishAt(
	ctx context.Context,
	event *Event,
	publishAt time.Time,
) error

func (*Publisher) PublishRaw

func (p *Publisher) PublishRaw(
	ctx context.Context,
	body []byte,
) (err error, recoverable bool)

type Questionnaire

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

func NewQuestionnaire

func NewQuestionnaire(
	logger *zap.Logger,
	redis *redis.Client,
	publisher *Publisher,
) *Questionnaire

func (*Questionnaire) Do

func (q *Questionnaire) Do(ctx context.Context, event *Event) (bool, error)

func (*Questionnaire) Redo

func (q *Questionnaire) Redo(event *Event) error

Redo Will register a questionnaire event again. Helper function to easily remake questionnaires with the same payloads and keys

func (*Questionnaire) Register

func (q *Questionnaire) Register(
	key string,
	filter QuestionnaireFilter,
	payload map[string]interface{},
) error

func (*Questionnaire) RegisterWithExpiration

func (q *Questionnaire) RegisterWithExpiration(
	key string,
	filter QuestionnaireFilter,
	payload map[string]interface{},
	expiration time.Duration,
) error

type QuestionnaireFilter

type QuestionnaireFilter struct {
	GuildID   string
	ChannelID string
	UserID    string
	Type      Type
}

QuestionnaireFilter matches the fields with the events

type QuestionnaireMatch

type QuestionnaireMatch struct {
	Key     string
	Payload map[string]interface{}
	Filter  QuestionnaireFilter
}

type QuickactionRemind

type QuickactionRemind struct {
	GuildID   string
	ChannelID string
	MessageID string
	Emoji     *discordgo.Emoji

	ToUserID string
}

type ServerlistServerExpire

type ServerlistServerExpire struct {
	ID         uint
	GuildID    string
	InviteCode string
	BotID      string
}

type SpanContext

type SpanContext struct {
	Values map[string]string `json:"values"`
}

func (*SpanContext) Get

func (sp *SpanContext) Get(key string) string

func (*SpanContext) Set

func (sp *SpanContext) Set(key, value string)

type Storage

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

func NewStorage

func NewStorage(
	logger *zap.Logger,
	db *gorm.DB,
	bucket *blob.Bucket,
) *Storage

type Type

type Type string

Type defines the type for a Event

const (
	// Discord Events
	ChannelCreateType            Type = "discord_channel_create"
	ChannelDeleteType            Type = "discord_channel_delete"
	ChannelPinsUpdateType        Type = "discord_channel_pins_update"
	ChannelUpdateType            Type = "discord_channel_update"
	GuildBanAddType              Type = "discord_guild_ban_add"
	GuildBanRemoveType           Type = "discord_guild_ban_remove"
	GuildCreateType              Type = "discord_guild_create"
	GuildDeleteType              Type = "discord_guild_delete"
	GuildEmojisUpdateType        Type = "discord_guild_emojis_update"
	GuildMemberAddType           Type = "discord_guild_member_add"
	GuildMemberRemoveType        Type = "discord_guild_member_remove"
	GuildMemberUpdateType        Type = "discord_guild_member_update"
	GuildMembersChunkType        Type = "discord_guild_members_chunk"
	GuildRoleCreateType          Type = "discord_guild_role_create"
	GuildRoleDeleteType          Type = "discord_guild_role_delete"
	GuildRoleUpdateType          Type = "discord_guild_role_update"
	GuildUpdateType              Type = "discord_guild_update"
	GuildIntegrationsUpdateType  Type = "discord_guild_integrations_update"
	MessageCreateType            Type = "discord_message_create"
	MessageDeleteType            Type = "discord_message_delete"
	MessageDeleteBulkType        Type = "discord_message_delete_bulk"
	MessageReactionAddType       Type = "discord_message_reaction_add"
	MessageReactionRemoveType    Type = "discord_message_reaction_remove"
	MessageReactionRemoveAllType Type = "discord_message_reaction_remove_all"
	MessageUpdateType            Type = "discord_message_update"
	PresenceUpdateType           Type = "discord_presence_update"
	UserUpdateType               Type = "discord_user_update"
	VoiceStateUpdateType         Type = "discord_voice_state_update"
	VoiceServerUpdateType        Type = "discord_voice_server_update"
	WebhooksUpdateType           Type = "discord_webhooks_update"
	InteractionCreateType        Type = "discord_interaction_create"
	// Cacophony Events
	CacophonyBucketUpdate           Type = "cacophony_bucket_update"
	CacophonyServerlistServerExpire Type = "cacophony_serverlist_server_expire"
	CacophonyQuickactionRemind      Type = "cacophony_quickaction_remind"
	CacophonyQuestionnaireMatch     Type = "cacophony_questionnaire_match"
	CacophonyAutomodWait            Type = "cacophony_automod_wait"
	CacophonyEventlogUpdate         Type = "cacophony_eventlog_update"
	CacophonyDiffGuild              Type = "cacophony_diff_guild"
	CacophonyDiffMember             Type = "cacophony_diff_member"
	CacophonyDiffChannel            Type = "cacophony_diff_channel"
	CacophonyDiffRole               Type = "cacophony_diff_role"
	CacophonyDiffEmoji              Type = "cacophony_diff_emoji"
	CacophonyDiffWebhooks           Type = "cacophony_diff_webhooks"
	CacophonyDiffInvites            Type = "cacophony_diff_invites"
	CacophonyGuildMemberAddExtra    Type = "cacophony_extra_guild_member_add"
)

defines various Event Types

type UserError

type UserError struct {
	Message string
	Err     error
}

func AsUserError

func AsUserError(err error) *UserError

func NewUserError

func NewUserError(message string) *UserError

func (UserError) Error

func (e UserError) Error() string

func (UserError) Unwrap

func (e UserError) Unwrap() error

type UserStorageInfo

type UserStorageInfo struct {
	FileCount        int
	StorageUsed      int
	StorageAvailable int
}

Jump to

Keyboard shortcuts

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