shop

package
v0.0.0-...-a879f8e Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CUSTOM_COMMAND             = "custom_command"
	CUSTOM_COMMAND_NAME        = "Custom Command"
	CUSTOM_COMMAND_DESCRIPTION = "Custom command that may be used on this server"
)
View Source
const (
	CONFIG_COLLECTION    = "shop_configs"
	SHOP_ITEM_COLLECTION = "shop_items"
	PURCHASE_COLLECTION  = "shop_purchases"
	MEMBER_COLLECTION    = "shop_members"
)
View Source
const (
	PLUGIN_NAME        = "shop"
	PURCHASES_PER_PAGE = 5
)
View Source
const (
	APPROVED  = "approved"
	DENIED    = "denied"
	PENDING   = "pending"
	PURCHASED = "purchased"
)
View Source
const (
	MAX_SHOP_ITEMS_DISPLAYED = 25
)
View Source
const (
	ROLE = "role"
)
View Source
const (
	SHOP_BAN = "shop"
)

Variables

This section is empty.

Functions

func SetDB

func SetDB(d *mongo.MongoDB)

SetDB sets the database for testing purposes

func Start

func Start()

creates and registers the plugin for the banking system

Types

type Config

type Config struct {
	ID             primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
	GuildID        string             `json:"guild_id" bson:"guild_id"`
	ChannelID      string             `json:"channel_id" bson:"channel_id"`
	MessageID      string             `json:"message_id" bson:"message_id"`
	ModChannelID   string             `json:"mod_channel_id" bson:"mod_channel_id"`
	NotificationID string             `json:"notification_id" bson:"notification_id"`
}

Config represents the configuration for the shop in a guild.

func GetConfig

func GetConfig(guildID string) *Config

GetConfig reads the configuration from the database. If the config does not exist, then one is created.

func (*Config) SetChannel

func (c *Config) SetChannel(channelID string)

SetChannel sets the channel to which to publish the shop items

func (*Config) SetMessageID

func (c *Config) SetMessageID(messageID string)

SetMessageID saves the interaction used to publish the shop items.

func (*Config) SetModChannel

func (c *Config) SetModChannel(channelID string)

SetModChannel sets the channel to which to publish the shop purchases and expirations.

func (*Config) SetNotificationID

func (c *Config) SetNotificationID(id string)

SetModChannel sets the channel to which to notify a user (e.g., ModMail) about an action to take to complete a member's purchase.

func (*Config) String

func (c *Config) String() string

String returns a string representation of the config.

type CustomCommand

type CustomCommand ShopItem

CustomCommand represents a custom command item in the shop.

func GetCustomCommand

func GetCustomCommand(guildID string, name string) *CustomCommand

GetCustomCommand retrieves a custom command from the shop by its name for a specific guild.

func NewCustomCommand

func NewCustomCommand(guildID string, name string, description string, price int) *CustomCommand

NewCustomCommand creates a new command for the shop.

func (*CustomCommand) AddToShop

func (cc *CustomCommand) AddToShop(s *Shop) error

AddToShop adds the command to the shop. If the command already exists, an error is returned.

func (*CustomCommand) Purchase

func (cc *CustomCommand) Purchase(s *discordgo.Session, memberID string) (*Purchase, error)

Purchase allows a member to purchase the command from the shop.

func (*CustomCommand) RemoveFromShop

func (cc *CustomCommand) RemoveFromShop(s *Shop) error

RemoveFromShop removes the command from the shop. If the command does not exist, an error is returned.

func (*CustomCommand) Update

func (cc *CustomCommand) Update(name string, description string, price int, duration string, autoRenewable bool) error

Update updates the command's properties in the shop.

type Member

type Member struct {
	ID           primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
	GuildID      string             `json:"guild_id,omitempty" bson:"guild_id,omitempty"`
	MemberID     string             `json:"member_id,omitempty" bson:"member_id,omitempty"`
	Restrictions []string           `json:"restrictions,omitempty" bson:"restrictions,omitempty"`
}

Member represents a member of a guild with restrictions on what they can or cannot do in a shop.

func GetMember

func GetMember(guildID, memberID string) *Member

GetMember retrieves a member from the database, creating one if it doesn't exist.

func (*Member) AddRestriction

func (m *Member) AddRestriction(restriction string) error

AddRestriction adds a restriction to the member.

func (*Member) HasRestriction

func (m *Member) HasRestriction(restriction string) bool

HasRestriction checks if the member has a specific restriction.

func (*Member) RemoveRestriction

func (m *Member) RemoveRestriction(restriction string) error

RemoveRestriction removes a restriction from the member.

type Plugin

type Plugin struct{}

Plugin is the plugin for the banking system used by the bot

func (*Plugin) GetAdminHelp

func (plugin *Plugin) GetAdminHelp() []string

GetAdminHelp returns the admin help for the banking system

func (*Plugin) GetCommandHandlers

func (plugin *Plugin) GetCommandHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)

GetCommandHandlers returns the command handlers for the banking system

func (*Plugin) GetCommands

func (plugin *Plugin) GetCommands() []*discordgo.ApplicationCommand

GetCommands returns the commands for the banking system

func (*Plugin) GetComponentHandlers

func (plugin *Plugin) GetComponentHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)

GetComponentHandlers returns the component handlers for the banking system

func (*Plugin) GetHelp

func (plugin *Plugin) GetHelp() []string

GetHelp returns the member help for the banking system

func (*Plugin) GetName

func (plugin *Plugin) GetName() string

GetName returns the name of the banking system plugin

func (*Plugin) Initialize

func (plugin *Plugin) Initialize(b *discord.Bot, d *mongo.MongoDB)

Initialize saves the Discord bot to be used by the banking system

func (*Plugin) Status

func (plugin *Plugin) Status() discord.PluginStatus

Status returns the status of the heist game. This is used to determine if the plugin is running or not.

func (*Plugin) Stop

func (plugin *Plugin) Stop()

Stop stops the heist game. This is called when the bot is shutting down.

type Purchase

type Purchase struct {
	ID          primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
	GuildID     string             `json:"guild_id" bson:"guild_id"`
	MemberID    string             `json:"member_id" bson:"member_id"`
	Item        *ShopItem          `json:"item" bson:"item,inline"`
	Status      string             `json:"status" bson:"status"`
	PurchasedOn time.Time          `json:"purchased_on" bson:"purchased_on"`
	ExpiresOn   time.Time          `json:"expires_on" bson:"expires_on"`
	AutoRenew   bool               `json:"auto_renew" bson:"auto_renew"`
	IsExpired   bool               `json:"is_expired" bson:"is_expired"`
}

Purchase is a purchase made from the shop.

func GetAllPurchases

func GetAllPurchases(guildID string, memberID string) []*Purchase

GetAllRoles returns all the purchases made by a member in the guild.

func GetPurchase

func GetPurchase(guildID string, memberID string, itemName string, itemType string) *Purchase

GetPurchase returns the purchase made by a member in the guild for the given item name. If the purchase does not exist, nil is returned.

func PurchaseItem

func PurchaseItem(guildID, memberID string, item *ShopItem, status string, renew bool) (*Purchase, error)

PurchaseItem creates a new Purchase with the given guild ID, member ID, and a purchasable shop item.

func (*Purchase) HasExpired

func (p *Purchase) HasExpired() bool

Determine if a purchase has expired. This marks the purchase as expired and undoes the effects of the purchase if it has expired.

func (*Purchase) Return

func (p *Purchase) Return() error

Return the purchase to the shop.

func (*Purchase) String

func (p *Purchase) String() string

String returns a string representation of the purchase.

func (*Purchase) Update

func (p *Purchase) Update(autoRenew bool) error

Update updates the purchase with the given autoRenew value.

type Role

type Role ShopItem

Role represents a role item in the shop.

func GetRole

func GetRole(guildID string, name string) *Role

GetRole retrieves a role from the shop by its name for a specific guild.

func NewRole

func NewRole(guildID string, name string, description string, price int, duration string, autoRenewable bool) *Role

NewRole creates a new role for the shop.

func (*Role) AddToShop

func (r *Role) AddToShop(s *Shop) error

AddToShop adds the role to the shop. If the role already exists, an error is returned.

func (*Role) Purchase

func (r *Role) Purchase(memberID string, renew bool) (*Purchase, error)

Purchase allows a member to purchase the role from the shop.

func (*Role) RemoveFromShop

func (r *Role) RemoveFromShop(s *Shop) error

RemoveFromShop removes the role from the shop. If the role does not exist, an error is returned.

func (*Role) Update

func (r *Role) Update(name string, description string, price int, duration string, autoRenewable bool) error

Update updates the role's properties in the shop.

type Shop

type Shop struct {
	GuildID string      // Guild (server) for the shop
	Items   []*ShopItem // All items available in the shop
}

The shop for a guild. The shop contains all items available for purchase.

func GetShop

func GetShop(guildID string) *Shop

GetShop returns the shop for the guild.

func (*Shop) GetShopItem

func (s *Shop) GetShopItem(name string, itemType string) *ShopItem

GetShopItems finds an item in the shop. If the item does not exist then nil is returned.

type ShopItem

type ShopItem struct {
	ID            primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
	GuildID       string             `json:"guild_id" bson:"guild_id"`
	Name          string             `json:"name" bson:"name"`
	Description   string             `json:"description" bson:"description"`
	Type          string             `json:"type" bson:"type"`
	Price         int                `json:"price" bson:"price"`
	Duration      string             `json:"duration,omitempty" bson:"duration,omitempty"`
	AutoRenewable bool               `json:"auto_renewable,omitempty" bson:"auto_renewable,omitempty"`
}

ShopItem represents an item in the shop, which represents any purchasable item.

func (*ShopItem) String

func (item *ShopItem) String() string

String returns a string representation of the Role.

Jump to

Keyboard shortcuts

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