botlib

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2023 License: GPL-3.0 Imports: 33 Imported by: 2

Documentation

Overview

Copyright (C) 2022-2023  sabafly

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var (
	Color   int    = 0xffffff
	BotName string = "developer bot"
)
View Source
var EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18,20}>`)

Functions

func ActivitiesNameString

func ActivitiesNameString(locale discord.Locale, activity discord.Activity) (str string)

アクティビティ名をアクティビティの種類によって渡された言語に翻訳して返す

func ErrorMessageEmbed

func ErrorMessageEmbed(locale discord.Locale, t string, opts ...ReturnErrOption) []discord.Embed

エラーメッセージ埋め込みを作成する

func ErrorRespond

func ErrorRespond(locale discord.Locale, err error) discord.MessageCreate

エラーが発生したことを返すレスポンスを作成する Deprecated: use ErrorTraceEmbed()

func ErrorTraceEmbed

func ErrorTraceEmbed(locale discord.Locale, err error) []discord.Embed

エラートレース埋め込みを作成する

func FormatComponentEmoji

func FormatComponentEmoji(e discord.ComponentEmoji) string

func GetCustomEmojis

func GetCustomEmojis(str string) []discord.Emoji

func GetHighestRolePosition

func GetHighestRolePosition(role map[snowflake.ID]discord.Role) (int, snowflake.ID)

func MessageLogDetails

func MessageLogDetails(m []MessageLog) (day, week, all int, channelID snowflake.ID)

func Number2Emoji

func Number2Emoji(n int) string

func ParseComponentEmoji

func ParseComponentEmoji(str string) discord.ComponentEmoji

func ReturnErr

func ReturnErr(interaction responsibleInteraction, err error, opts ...ReturnErrOption) error

func ReturnErrMessage

func ReturnErrMessage(interaction responsibleInteraction, tr string, opts ...ReturnErrOption) error

func ReturnErrMessageEphemeral deprecated

func ReturnErrMessageEphemeral(interaction responsibleInteraction, tr, fallback_title, fallback_description string, ephemeral bool, data ...any) error

Deprecated: use ReturnErrMessage() with WithEphemeral()

func SendWebhook

func SendWebhook(client bot.Client, channelID snowflake.ID, data discord.WebhookMessageCreate) (st *discord.Message, err error)

func SetEmbedProperties

func SetEmbedProperties(embed discord.Embed) discord.Embed

埋め込みの色、フッター、タイムスタンプを設定する

func SetEmbedsProperties

func SetEmbedsProperties(embeds []discord.Embed) []discord.Embed

埋め込みの色、フッター、タイムスタンプを設定する

func StatusString

func StatusString(status discord.OnlineStatus) (str string)

渡されたステータスの絵文字を返す

Types

type Bot

type Bot[DB db.DB] struct {
	Logger    log.Logger
	Client    bot.Client
	OAuth     oauth2.Client
	Paginator *paginator.Manager
	Config    Config
	Version   string
	Handler   *handler.Handler
	DB        DB
}

func New

func New[DB db.DB](logger log.Logger, version string, config Config) *Bot[DB]

func (*Bot[DB]) CheckDev

func (b *Bot[DB]) CheckDev(id snowflake.ID) bool

func (*Bot[DB]) OnGuildJoin

func (b *Bot[DB]) OnGuildJoin(g *events.GuildJoin)

func (*Bot[DB]) OnGuildLeave

func (b *Bot[DB]) OnGuildLeave(g *events.GuildLeave)

func (*Bot[DB]) OnGuildMemberJoin

func (b *Bot[DB]) OnGuildMemberJoin(m *events.GuildMemberJoin)

func (*Bot[DB]) OnGuildMemberLeave

func (b *Bot[DB]) OnGuildMemberLeave(m *events.GuildMemberLeave)

func (*Bot[DB]) RefreshPresence

func (b *Bot[DB]) RefreshPresence()

func (*Bot[DB]) SetupBot

func (b *Bot[DB]) SetupBot(listeners ...bot.EventListener)

type Config

type Config struct {
	DevMode            bool           `json:"dev_mode"`
	DevOnly            bool           `json:"dev_only"`
	DevGuildIDs        []snowflake.ID `json:"dev_guild_id"`
	DevUserIDs         []snowflake.ID `json:"dev_user_id"`
	LogLevel           string         `json:"log_level"`
	Token              string         `json:"token"`
	DMPermission       bool           `json:"dm_permission"`
	ShouldSyncCommands bool           `json:"sync_commands"`
	ASyncEventHandler  bool           `json:"async_event_handler"`
	DBConfig           db.DBConfig    `json:"db_config"`
	Dislog             DislogConfig   `json:"dislog"`
	ClientID           snowflake.ID   `json:"client_id"`
	Secret             string         `json:"secret"`
	HttpIp             string         `json:"http_ip"`
	RedirectLink       string         `json:"redirect_link"`
	RootUri            string         `json:"root_uri"`
}

func LoadConfig

func LoadConfig(config_filepath string) (*Config, error)

type DislogConfig

type DislogConfig struct {
	Enabled        bool         `json:"enabled"`
	WebhookChannel snowflake.ID `json:"webhook_channel"`
	WebhookID      snowflake.ID `json:"webhook_id"`
	WebhookToken   string       `json:"webhook_token"`
}

type MessageLog

type MessageLog struct {
	ID        snowflake.ID
	GuildID   snowflake.ID
	ChannelID snowflake.ID
	UserID    snowflake.ID
	Content   string
	Bot       bool
}

type ReturnErrCfg added in v1.5.0

type ReturnErrCfg struct {
	Ephemeral           bool   `json:"ephemeral"`
	TranslateData       []any  `json:"translate_data"`
	FallBackTitle       string `json:"fallback_title"`
	FallBackDescription string `json:"fallback_description"`
}

type ReturnErrOption added in v1.5.0

type ReturnErrOption func(*ReturnErrCfg)

func WithEphemeral added in v1.5.0

func WithEphemeral(enabled bool) ReturnErrOption

func WithFallBackDescription added in v1.5.0

func WithFallBackDescription(desc string) ReturnErrOption

func WithFallbackTitle added in v1.5.0

func WithFallbackTitle(title string) ReturnErrOption

func WithTranslateData added in v1.5.0

func WithTranslateData(data ...any) ReturnErrOption

Jump to

Keyboard shortcuts

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