bot

package
v0.0.0-...-0abf00b Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

SPDX-License-Identifier: AGPL-3.0-only

Index

Constants

View Source
const ErrUnknownEvent = errors.Sentinel("unknown event type")
View Source
const Reschedule = errors.Sentinel("reschedule event")

Return Reschedule if the event should be rescheduled (offset by the duration returned from Offset)

Variables

View Source
var Commands = []api.CreateCommandData{

	{
		Name:        "bubble",
		Description: "Bubble wrap!",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.IntegerOption{
				OptionName:  "size",
				Description: "Size of the bubble wrap (default 10)",
				Min:         option.NewInt(1),
				Max:         option.NewInt(13),
			},
			&discord.BooleanOption{
				OptionName:  "prepop",
				Description: "Whether to pre-pop some bubbles",
			},
			&discord.BooleanOption{
				OptionName:  "ephemeral",
				Description: "Whether to send the bubble wrap as a message only visible to you",
			},
		},
	},
	{
		Name:        "linkto",
		Description: "Move a conversation to another channel.",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.ChannelOption{
				OptionName:   "channel",
				ChannelTypes: []discord.ChannelType{discord.GuildText, discord.GuildNews, discord.GuildPublicThread, discord.GuildPrivateThread, discord.GuildNewsThread},
				Required:     true,
				Description:  "The channel to link to.",
			},
			&discord.StringOption{
				OptionName:  "topic",
				Required:    false,
				Description: "The topic.",
			},
		},
	},
	{
		Name:        "pride",
		Description: "Add a pride flag circle to your profile picture!",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.StringOption{
				OptionName:  "flag",
				Description: "Which flag to use.",
				Required:    false,
			},
			&discord.StringOption{
				OptionName:  "pk-member",
				Description: "Which PluralKit member's avatar to add a pride flag to.",
				Required:    false,
			},
		},
	},
	{
		Name:        "sampa",
		Description: "Convert X-SAMPA to IPA.",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.StringOption{
				OptionName:  "text",
				Description: "The text to convert to IPA.",
				Required:    true,
			},
		},
	},
	{
		Name:        "reminders",
		Description: "Show your reminders.",
		Type:        discord.ChatInputCommand,
	},
	{
		Name:        "remindme",
		Description: "Show your reminders.",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.StringOption{
				OptionName:  "when",
				Description: "When or in how long to remind you.",
				Required:    true,
			},
			&discord.StringOption{
				OptionName:  "text",
				Description: "What to remind you of.",
			},
		},
	},
	{
		Name:        "level",
		Description: "Use levels.",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.SubcommandOption{
				OptionName:  "show",
				Description: "Show your or another user's level.",
				Options: []discord.CommandOptionValue{&discord.UserOption{
					OptionName:  "user",
					Description: "The user to show.",
					Required:    false,
				}},
			},
			&discord.SubcommandOption{
				OptionName:  "leaderboard",
				Description: "Show this server's leaderboard.",
				Options: []discord.CommandOptionValue{&discord.BooleanOption{
					OptionName:  "full",
					Description: "Whether to show the full leaderboard (including users who have left the server)",
					Required:    false,
				}},
			},
		},
	},
	{
		Name:        "info",
		Description: "Show information about a user, role, or this server.",
		Type:        discord.ChatInputCommand,
		Options: discord.CommandOptions{
			&discord.SubcommandOption{
				OptionName:  "user",
				Description: "Show info about a user.",
				Options: []discord.CommandOptionValue{&discord.UserOption{
					OptionName:  "user",
					Description: "The user to look up.",
					Required:    false,
				}},
			},
		},
	},

	{
		Name: "Show user avatar",
		Type: discord.UserCommand,
	},
}

Functions

func IsOurProblem

func IsOurProblem(e error) bool

IsOurProblem checks if an error is "our problem", as in, should be in the logs and reported to Sentry. Will be expanded eventually once we get more insight into what type of errors we get.

Types

type Bot

type Bot struct {
	*bcrbot.Bot

	Interactions *bcr2.Router

	Config      *common.BotConfig
	Sugar       *zap.SugaredLogger
	DB          *db.DB
	Scheduler   *Scheduler
	Chi         *chi.Mux
	EmbedColour discord.Color

	GuildLogWebhook *webhook.Client

	Counters struct {
		Mu sync.Mutex

		Mentions int
		Messages int
	}

	Hub *sentry.Hub

	PK *pkgo.Session

	ValidNodes []string
	// contains filtered or unexported fields
}

Bot is the main bot struct

func New

func New(
	bot *bcrbot.Bot,
	sugar *zap.SugaredLogger,
	db *db.DB,
	config *common.BotConfig) *Bot

New creates a new instance of Bot

func (*Bot) Add

func (bot *Bot) Add(fns ...func(*Bot) (string, []*bcr.Command))

Add adds a module to the bot

func (*Bot) CacheLen

func (bot *Bot) CacheLen() int64

CacheLen gets the size of the member cache

func (*Bot) CheckAdmin

func (bot *Bot) CheckAdmin(ctx *bcr.CommandContext) (err error)

func (*Bot) CheckHelper

func (bot *Bot) CheckHelper(ctx *bcr.CommandContext) (err error)

func (*Bot) CheckMod

func (bot *Bot) CheckMod(ctx *bcr.CommandContext) (err error)

func (*Bot) CheckPermissions

func (bot *Bot) CheckPermissions(ctx *bcr.Context, routing bool) (name string, allowed bool, data api.SendMessageData)

func (*Bot) CheckPrefix

func (bot *Bot) CheckPrefix(m discord.Message) int

CheckPrefix checks the prefix

func (*Bot) Commands

func (bot *Bot) Commands() []api.CreateCommandData

func (*Bot) GuildCreate

func (bot *Bot) GuildCreate(g *gateway.GuildCreateEvent)

GuildCreate logs the bot joining a server, and creates a database entry if one doesn't exist

func (*Bot) InitValidPermissionNodes

func (bot *Bot) InitValidPermissionNodes()

func (*Bot) Member

func (bot *Bot) Member(guildID discord.GuildID, userID discord.UserID) (m discord.Member, err error)

Member gets a member from the cache, or tries fetching it from Discord

func (*Bot) Members

func (bot *Bot) Members(guildID discord.GuildID) (members []discord.Member)

Members gets all *cached* members for a guild. Members are sorted by their ID.

func (*Bot) MessageCreate

func (bot *Bot) MessageCreate(m *gateway.MessageCreateEvent)

MessageCreate is run on a message create event

func (*Bot) NoDM

func (bot *Bot) NoDM(ctx *bcr.CommandContext) (err error)

func (*Bot) NodeLevel

func (bot *Bot) NodeLevel(guildID discord.GuildID, node string) common.Node

func (*Bot) PagedEmbed

func (bot *Bot) PagedEmbed(ctx *bcr.Context, embeds []discord.Embed, timeout time.Duration) (msg *discord.Message, err error)

PagedEmbed ...

func (*Bot) Report

func (bot *Bot) Report(ctx *bcr.Context, e error) (err error)

Report wraps around both ReportCtx and ReportSlash

func (*Bot) ReportInteraction

func (bot *Bot) ReportInteraction(c bcr2.HasContext, e error) (err error)

ReportInteraction is like ReportCtx but takes a SlashContext instead

func (*Bot) RequireNode

func (bot *Bot) RequireNode(required string) bcr.Check[*bcr.CommandContext]

func (*Bot) ShowText

func (bot *Bot) ShowText(w http.ResponseWriter, title, header, text string, v ...interface{})

func (*Bot) Start

func (bot *Bot) Start(ctx context.Context) error

Start wraps around Router.ShardManager.Open()

func (*Bot) UserBotPermissions

func (bot *Bot) UserBotPermissions(user discord.User, member *discord.Member, guild *discord.Guild) common.PermissionLevel

type Event

type Event interface {
	Execute(ctx context.Context, id int64, bot *Bot) error
	Offset() time.Duration
}

Event is any event that can be scheduled. Execute is called when the event is due to fire, Offset is called to determine how much to move the event.

type Module

type Module interface {
	String() string
	Commands() []*bcr.Command
}

Module is a single module/category of commands

type Scheduler

type Scheduler struct {
	*db.DB
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(bot *Bot, db *db.DB) *Scheduler

func (*Scheduler) Add

func (s *Scheduler) Add(t time.Time, v Event) (id int64, err error)

func (*Scheduler) AddType

func (s *Scheduler) AddType(events ...Event)

AddType adds event common. These should be *pointers*, anything else will panic, even if it implements Event!

func (*Scheduler) Remove

func (s *Scheduler) Remove(id int64) error

func (*Scheduler) Reschedule

func (s *Scheduler) Reschedule(id int64, dur time.Duration) error

func (*Scheduler) Start

func (s *Scheduler) Start()

Start starts the scheduler. *This function is blocking!*

Jump to

Keyboard shortcuts

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