welcomer

package module
v0.0.0-...-7167ae2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: AGPL-3.0 Imports: 22 Imported by: 4

Documentation

Index

Constants

View Source
const (
	EmojiCheck   = "<:check:1196902761627914402>"
	EmojiCross   = "<:cross:1196902764048031744>"
	EmojiNeutral = "<:neutral:1196903241959620730>"

	EmojiRock = "<:rock:732274836038221855>"
)
View Source
const (
	CustomEventInvokeWelcomer = "WELCOMER_INVOKE_WELCOMER"
	CustomEventInvokeLeaver   = "WELCOMER_INVOKE_LEAVER"

	CustomEventInvokeTempChannels       = "WELCOMER_INVOKE_TEMPCHANNELS"
	CustomEventInvokeTempChannelsRemove = "WELCOMER_INVOKE_TEMPCHANNELS_REMOVE"

	CustomEventInvokeBorderwall           = "WELCOMER_INVOKE_BORDERWALL"
	CustomEventInvokeBorderwallCompletion = "WELCOMER_INVOKE_BORDERWALL_COMPLETION"
)
View Source
const (
	PatreonBase = "https://www.patreon.com/api/oauth2/v2/"
	CampaignID  = "1150593"
)

Variables

View Source
var (
	EmojiMessageBadge = discord.Emoji{ID: 987044175943970867, Name: "messagebadge"}
	EmojiShieldAlert  = discord.Emoji{ID: 987044177160331322, Name: "shieldalert"}
	EmojiCheckMark    = discord.Emoji{ID: 586907765662941185, Name: "checkboxmarkedoutline"}

	SupportInvite = "https://discord.gg/kQJz33ExK2"
	WebsiteURL    = "https://" + os.Getenv("DOMAIN") // https://welcomer.gg
)
View Source
var (
	ErrMembershipAlreadyInUse = errors.New("membership is already in use")
	ErrMembershipInvalid      = errors.New("membership is invalid")
	ErrMembershipExpired      = errors.New("membership has expired")
	ErrMembershipNotInUse     = errors.New("membership is not in use")
	ErrUnhandledMembership    = errors.New("membership type is not handled")
	ErrTransactionNotComplete = errors.New("transaction not completed")
)
View Source
var CountryMapping = map[string]Currency{
	"IN": CurrencyINR,
}
View Source
var SKUPricing = map[SKUName]PricingSKU{
	SKUCustomBackgrounds: {
		ID:             SKUCustomBackgrounds,
		Name:           "Custom Backgrounds",
		Description:    "One-time purchase to unlock custom welcome backgrounds for your server.",
		MembershipType: database.MembershipTypeCustomBackgrounds,
		SoftDescriptor: "Backgrounds",
		MonthCount:     -1,
		Costs: map[Currency]string{
			CurrencyEUR: "12.00",
			CurrencyGBP: "10.00",
			CurrencyUSD: "12.00",
			CurrencyINR: "300",
		},
	},
	SKUWelcomerPro: {
		ID:             SKUWelcomerPro,
		Name:           "Welcomer Pro",
		Description:    "Unlock all Welcomer Pro features for your server.",
		MembershipType: database.MembershipTypeWelcomerPro,
		SoftDescriptor: "Pro",
		MonthCount:     1,
		Costs: map[Currency]string{
			CurrencyEUR: "8.00",
			CurrencyGBP: "7.00",
			CurrencyUSD: "8.00",
			CurrencyINR: "300",
		},
	},
	SKUWelcomerProBiAnnual: {
		ID:             SKUWelcomerProBiAnnual,
		Name:           "Welcomer Pro",
		Description:    "Unlock all Welcomer Pro features for your server.",
		MembershipType: database.MembershipTypeWelcomerPro,
		SoftDescriptor: "Pro",
		MonthCount:     6,
		Costs: map[Currency]string{
			CurrencyEUR: "40.00",
			CurrencyGBP: "35.00",
			CurrencyUSD: "40.00",
			CurrencyINR: "1500",
		},
	},
	SKUWelcomerProAnnual: {
		ID:             SKUWelcomerProAnnual,
		Name:           "Welcomer Pro",
		Description:    "Unlock all Welcomer Pro features for your server.",
		MembershipType: database.MembershipTypeWelcomerPro,
		SoftDescriptor: "Pro",
		MonthCount:     12,
		Costs: map[Currency]string{
			CurrencyEUR: "80.00",
			CurrencyGBP: "70.00",
			CurrencyUSD: "80.00",
			CurrencyINR: "3000",
		},
	},
}

Functions

func AcquireSession

func AcquireSession(ctx context.Context, sub *subway.Subway, managerName string) (session *discord.Session, err error)

func AddManagerNameToContext

func AddManagerNameToContext(ctx context.Context, v string) context.Context

ManagerName context handler.

func AddMembershipToServer

func AddMembershipToServer(ctx context.Context, logger zerolog.Logger, queries *database.Queries, membership database.GetUserMembershipsByUserIDRow, guildID discord.Snowflake) (newMembership database.UpdateUserMembershipParams, err error)

func AddPoolToContext

func AddPoolToContext(ctx context.Context, v *pgxpool.Pool) context.Context

Arguments context handler.

func AddQueriesToContext

func AddQueriesToContext(ctx context.Context, v *database.Queries) context.Context

Queries context handler.

func AssertLength

func AssertLength(name string, expectedLength int, arguments ...interface{}) (err error)

func CheckGuildMemberships

func CheckGuildMemberships(memberships []*database.GetUserMembershipsByGuildIDRow) (hasWelcomerPro bool, hasCustomBackgrounds bool)

func CreateMembershipForUser

func CreateMembershipForUser(ctx context.Context, queries *database.Queries, userID discord.Snowflake, transactionUuid uuid.UUID, membershipType database.MembershipType, expiresAt time.Time, guildID *discord.Snowflake) error

func CreateTransactionForUser

func CreateTransactionForUser(ctx context.Context, queries *database.Queries, userID discord.Snowflake, platformType database.PlatformType, transactionStatus database.TransactionStatus, transactionID string, currencyCode string, amount string) (*database.UserTransactions, error)

func EnsureGuild

func EnsureGuild(ctx context.Context, queries *database.Queries, guildID discord.Snowflake) error

EnsureGuild will create or update a guild entry. This requires RequireMutualGuild to be called.

func EscapeStringForJSON

func EscapeStringForJSON(value string) string

EscapeStringForJSON escapes a string for JSON.

func FilterAssignableRoles

func FilterAssignableRoles(ctx context.Context, sandwichClient pb.SandwichClient, logger zerolog.Logger, guildID int64, applicationID int64, roleIDs []int64) (out []discord.Snowflake, err error)

func FormatString

func FormatString(funcs map[string]govaluate.ExpressionFunction, vars map[string]interface{}, message string) (string, error)

func GatherFunctions

func GatherFunctions() (funcs map[string]govaluate.ExpressionFunction)

func GatherVariables

func GatherVariables(eventCtx *sandwich.EventContext, member discord.GuildMember, guild discord.Guild, invite *discord.Invite, extraValues map[string]interface{}) (vars map[string]interface{})

func GetGuildMemberDisplayName

func GetGuildMemberDisplayName(member discord.GuildMember) string

func GetManagerNameFromContext

func GetManagerNameFromContext(ctx context.Context) string

func GetPoolFromContext

func GetPoolFromContext(ctx context.Context) *pgxpool.Pool

func GetQueriesFromContext

func GetQueriesFromContext(ctx context.Context) *database.Queries

func GetUserAvatar

func GetUserAvatar(user *discord.User) string

func GetUserDisplayName

func GetUserDisplayName(user *discord.User) string

func IncludeBorderwallVerifyButton

func IncludeBorderwallVerifyButton(messageParams discord.MessageParams, borderwallLink string) discord.MessageParams

func IncludeScamsButton

func IncludeScamsButton(messageParams discord.MessageParams) discord.MessageParams

func IncludeSentByButton

func IncludeSentByButton(messageParams discord.MessageParams, guildName string) discord.MessageParams

func IsCustomBackgroundsMembership

func IsCustomBackgroundsMembership(membershipType database.MembershipType) bool

func IsWelcomerProMembership

func IsWelcomerProMembership(membershipType database.MembershipType) bool

func MarshalTimeRolesJSON

func MarshalTimeRolesJSON(roles []GuildSettingsTimeRolesRole) (rolesJSON []byte)

func MemberHasElevation

func MemberHasElevation(discordGuild discord.Guild, member discord.GuildMember) bool

func OnPatreonActive

func OnPatreonActive(ctx context.Context, logger zerolog.Logger, queries *database.Queries, patreonUser database.PatreonUsers, patreonMember PatreonMember) error

Triggered when a patron is still pledging.

func OnPatreonLinked

func OnPatreonLinked(ctx context.Context, logger zerolog.Logger, queries *database.Queries, patreonUser PatreonUser, automatic bool) error

Triggers when a patreon account has been linked.

func OnPatreonNoLongerPledging

func OnPatreonNoLongerPledging(ctx context.Context, logger zerolog.Logger, queries *database.Queries, patreonUser database.PatreonUsers, patreonMember PatreonMember) error

Triggers when a patron is no longer pledging

func OnPatreonTierChanged

func OnPatreonTierChanged(ctx context.Context, logger zerolog.Logger, queries *database.Queries, beforePatreonUser *database.PatreonUsers, patreonUser database.CreateOrUpdatePatreonUserParams) error

Triggers when a patreon tier has changed.

func OnPatreonTierChanged_Fallback

func OnPatreonTierChanged_Fallback(ctx context.Context, logger zerolog.Logger, queries *database.Queries, beforePatreonUser *database.PatreonUsers, patreonUser database.CreateOrUpdatePatreonUserParams, e error) error

Triggers when a patreon tier has changed. Ran if OnPatreonTierChange failed to run.

func OnPatreonUnlinked

func OnPatreonUnlinked(ctx context.Context, logger zerolog.Logger, queries *database.Queries, patreonUser *database.PatreonUsers) error

Triggers when a patreon account has been unlinked.

func RemoveMembershipFromServer

func RemoveMembershipFromServer(ctx context.Context, logger zerolog.Logger, queries *database.Queries, membership database.GetUserMembershipsByUserIDRow) (newMembership database.UpdateUserMembershipParams, err error)

func RequireGuild

func RequireGuild(interaction discord.Interaction, handler BasicInteractionHandler) (*discord.InteractionResponse, error)

func RequireGuildElevation

func RequireGuildElevation(sub *subway.Subway, interaction discord.Interaction, handler BasicInteractionHandler) (*discord.InteractionResponse, error)

Types

type Attributes

type Attributes struct {
	CurrentlyEntitledAmountCents int64                   `json:"currently_entitled_amount_cents"`
	Email                        string                  `json:"email"`
	FullName                     string                  `json:"full_name"`
	ThumbUrl                     string                  `json:"thumb_url"`
	IsFollower                   bool                    `json:"is_follower"`
	LastChargeDate               time.Time               `json:"last_charge_date"`
	LastChargeStatus             LastChargeStatus        `json:"last_charge_status"`
	LifetimeSupportCents         int64                   `json:"lifetime_support_cents"`
	PatronStatus                 PatronStatus            `json:"patron_status"`
	SocialConnections            PatronSocialConnections `json:"social_connections"`
}

type BasicInteractionHandler

type BasicInteractionHandler func() (*discord.InteractionResponse, error)

type Currency

type Currency string
const (
	CurrencyEUR Currency = "EUR"
	CurrencyGBP Currency = "GBP"
	CurrencyINR Currency = "INR"
	CurrencyUSD Currency = "USD"
)

type CustomEventInvokeBorderwallCompletionStructure

type CustomEventInvokeBorderwallCompletionStructure struct {
	Member discord.GuildMember
}

type CustomEventInvokeBorderwallStructure

type CustomEventInvokeBorderwallStructure struct {
	Member discord.GuildMember
}

type CustomEventInvokeLeaverStructure

type CustomEventInvokeLeaverStructure struct {
	Interaction *discord.Interaction
	User        discord.User
	GuildID     discord.Snowflake
}

type CustomEventInvokeTempChannelsRemoveStructure

type CustomEventInvokeTempChannelsRemoveStructure struct {
	Interaction *discord.Interaction
	Member      discord.GuildMember
}

type CustomEventInvokeTempChannelsStructure

type CustomEventInvokeTempChannelsStructure struct {
	Interaction *discord.Interaction
	Member      discord.GuildMember
}

type CustomEventInvokeWelcomerStructure

type CustomEventInvokeWelcomerStructure struct {
	Interaction *discord.Interaction
	Member      discord.GuildMember
}

type GetPatreonMembersResponse

type GetPatreonMembersResponse struct {
	Data []struct {
		Attributes    Attributes    `json:"attributes"`
		Relationships Relationships `json:"relationships"`
	} `json:"data"`
	Included []struct {
		Attributes Attributes        `json:"attributes"`
		ID         discord.Snowflake `json:"id"`
		Type       string            `json:"type"`
	}
	Links struct {
		Next string `json:"next"`
	} `json:"links"`
}

type GuildSettingsTimeRolesRole

type GuildSettingsTimeRolesRole struct {
	Role    discord.Snowflake `json:"role_id"`
	Seconds int               `json:"seconds"`
}

func FilterAssignableTimeRoles

func FilterAssignableTimeRoles(ctx context.Context, sandwichClient pb.SandwichClient, logger zerolog.Logger, guildID int64, applicationID int64, timeRoles []GuildSettingsTimeRolesRole) (out []GuildSettingsTimeRolesRole, err error)

func UnmarshalTimeRolesJSON

func UnmarshalTimeRolesJSON(rolesJSON []byte) (roles []GuildSettingsTimeRolesRole)

type LastChargeStatus

type LastChargeStatus string
const (
	LastChargeStatusDeclined LastChargeStatus = "Declined"
	LastChargeStatusPaid     LastChargeStatus = "Paid"
	LastChargeStatusDeleted  LastChargeStatus = "Deleted"
	LastChargeStatusPending  LastChargeStatus = "Pending"
	LastChargeStatusRefunded LastChargeStatus = "Refunded"
	LastChargeStatusFraud    LastChargeStatus = "Fraud"
	LastChargeStatusOther    LastChargeStatus = "Other"
)

type OnInvokeBorderwallCompletionFuncType

type OnInvokeBorderwallCompletionFuncType func(eventCtx *sandwich.EventContext, member CustomEventInvokeBorderwallCompletionStructure) error

type OnInvokeBorderwallFuncType

type OnInvokeBorderwallFuncType func(eventCtx *sandwich.EventContext, member CustomEventInvokeBorderwallStructure) error

type OnInvokeLeaverFuncType

type OnInvokeLeaverFuncType func(eventCtx *sandwich.EventContext, member CustomEventInvokeLeaverStructure) error

type OnInvokeTempChannelsFuncType

type OnInvokeTempChannelsFuncType func(eventCtx *sandwich.EventContext, member CustomEventInvokeTempChannelsStructure) error

type OnInvokeTempChannelsRemoveFuncType

type OnInvokeTempChannelsRemoveFuncType func(eventCtx *sandwich.EventContext, member CustomEventInvokeTempChannelsRemoveStructure) error

type OnInvokeWelcomerFuncType

type OnInvokeWelcomerFuncType func(eventCtx *sandwich.EventContext, member CustomEventInvokeWelcomerStructure) error

type PatreonMember

type PatreonMember struct {
	PatreonUserID discord.Snowflake `json:"patreon_user_id"`
	EntitledTiers []PatreonTier     `json:"active_tier"`
	Attributes    Attributes        `json:"attributes"`
}

func GetAllPatreonMembers

func GetAllPatreonMembers(ctx context.Context, token string) ([]PatreonMember, error)

type PatreonTier

type PatreonTier int64
const (
	PatreonTierFree PatreonTier = 10503463

	PatreonTierUnpublishedWelcomerDonator PatreonTier = 3975266
	PatreonTierUnpublishedWelcomerPro1    PatreonTier = 3744919
	PatreonTierUnpublishedWelcomerPro3    PatreonTier = 3744921
	PatreonTierUnpublishedWelcomerPro5    PatreonTier = 3744926

	PatreonTierWelcomerPro PatreonTier = 23606682
)

func (*PatreonTier) UnmarshalJSON

func (s *PatreonTier) UnmarshalJSON(b []byte) error

type PatreonUser

type PatreonUser struct {
	ID                discord.Snowflake             `json:"id"`
	Email             string                        `json:"email"`
	FullName          string                        `json:"full_name"`
	SocialConnections PatreonUser_SocialConnections `json:"social_connections"`
	ThumbURL          string                        `json:"thumb_url"`
}

func IdentifyPatreonMember

func IdentifyPatreonMember(ctx context.Context, token string) (PatreonUser, error)

type PatreonUserOuter

type PatreonUserOuter struct {
	Data patreonUser `json:"data"`
}

type PatreonUser_Attributes

type PatreonUser_Attributes struct {
	Email             string                        `json:"email"`
	FullName          string                        `json:"full_name"`
	SocialConnections PatreonUser_SocialConnections `json:"social_connections"`
	ThumbURL          string                        `json:"thumb_url"`
}

type PatreonUser_Discord

type PatreonUser_Discord struct {
	UserID discord.Snowflake `json:"user_id"`
}

type PatreonUser_SocialConnections

type PatreonUser_SocialConnections struct {
	Discord PatreonUser_Discord `json:"discord"`
}

type PatronSocialConnections

type PatronSocialConnections struct {
	Discord struct {
		UserID discord.Snowflake `json:"user_id"`
	} `json:"discord"`
}

type PatronStatus

type PatronStatus string
const (
	PatreonStatusNeverPledged PatronStatus = ""
	PatreonStatusActive       PatronStatus = "active_patron"
	PatreonStatusDeclined     PatronStatus = "declined_patron"
	PatreonStatusFormer       PatronStatus = "former_patron"
)

type PricingSKU

type PricingSKU struct {
	ID                SKUName                 `json:"id"`
	Name              string                  `json:"name"`
	Description       string                  `json:"-"`
	MembershipType    database.MembershipType `json:"-"`
	SoftDescriptor    string                  `json:"-"` // This should be 13 characters or less.
	MonthCount        int                     `json:"month_count"`
	Costs             map[Currency]string     `json:"costs"`
	PatreonCheckoutId string                  `json:"patreon_checkout_id"`
}

type Relationships

type Relationships struct {
	CurrentlyEntitledTiers struct {
		Data []struct {
			ID PatreonTier `json:"id"`
		} `json:"data"`
	} `json:"currently_entitled_tiers"`
	User struct {
		Data struct {
			ID discord.Snowflake `json:"id"`
		} `json:"data"`
	} `json:"user"`
}

type SKUName

type SKUName string
const (
	SKUCustomBackgrounds   SKUName = "WEL/CBG"
	SKUWelcomerPro         SKUName = "WEL/1P1"
	SKUWelcomerProBiAnnual SKUName = "WEL/1P6"
	SKUWelcomerProAnnual   SKUName = "WEL/1P12"
)

type StubGuild

type StubGuild struct {
	Name    string            `json:"name"`
	Icon    string            `json:"icon"`
	Splash  string            `json:"splash"`
	Banner  string            `json:"banner"`
	ID      discord.Snowflake `json:"id"`
	Members int32             `json:"members"`
}

Guild represents a guild on discord.

func (StubGuild) String

func (s StubGuild) String() string

type StubInvite

type StubInvite struct {
	ExpiresAt StubTime          `json:"expires_at"`
	CreatedAt StubTime          `json:"created_at"`
	Inviter   StubUser          `json:"inviter"`
	ChannelID discord.Snowflake `json:"channel"`
	Code      string            `json:"code"`
	Uses      int32             `json:"uses"`
	MaxUses   int32             `json:"max_uses"`
	MaxAge    int32             `json:"max_age"`
	Temporary bool              `json:"temporary"`
}

Invite represents the invite used on discord.

type StubTime

type StubTime time.Time

func (StubTime) Relative

func (s StubTime) Relative() string

func (StubTime) String

func (s StubTime) String() string

type StubUser

type StubUser struct {
	CreatedAt     StubTime          `json:"created_at"`
	JoinedAt      StubTime          `json:"joined_at"`
	Name          string            `json:"name"`
	Username      string            `json:"username"`
	Discriminator string            `json:"discriminator"`
	GlobalName    string            `json:"global_name"`
	Mention       string            `json:"mention"`
	Avatar        string            `json:"avatar"`
	ID            discord.Snowflake `json:"id"`
	Bot           bool              `json:"bot"`
	Pending       bool              `json:"pending"`
}

StubUser represents a user on discord.

func (StubUser) String

func (s StubUser) String() string

type WelcomerInteractionsContextKey

type WelcomerInteractionsContextKey int
const (
	PoolKey WelcomerInteractionsContextKey = iota
	QueriesKey
	ManagerNameKey
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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