botlib

package
v2.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: GPL-3.0 Imports: 28 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"
)

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 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 GetWebhook added in v2.1.0

func GetWebhook(client bot.Client, channelID snowflake.ID) (id snowflake.ID, token string, err error)

func Number2Emoji

func Number2Emoji(n int) string

func ParseComponentEmoji

func ParseComponentEmoji(str string) discord.ComponentEmoji

func ReactionComponentEmoji added in v2.6.0

func ReactionComponentEmoji(e discord.ComponentEmoji) string

func ReturnErr

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

func ReturnErrMessage

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

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[T any] struct {
	Logger  log.Logger
	Client  bot.Client
	OAuth   oauth2.Client
	Config  Config
	Version string
	Handler *handler.Handler
	Self    T
}

func New

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

func (*Bot[DB]) CheckDev

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

func (*Bot[DB]) CheckDevGuild

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

func (*Bot[DB]) CheckDevUser

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

func (*Bot[T]) SetupBot

func (b *Bot[T]) 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"`
	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 ReturnErrCfg

type ReturnErrCfg struct {
	Ephemeral           bool
	TranslateData       []any
	FallBackTitle       string
	FallBackDescription string
	Update              bool
	UpdateClient        bot.Client
}

type ReturnErrOption

type ReturnErrOption func(*ReturnErrCfg)

func WithEphemeral

func WithEphemeral(enabled bool) ReturnErrOption

func WithFallBackDescription

func WithFallBackDescription(desc string) ReturnErrOption

func WithFallbackTitle

func WithFallbackTitle(title string) ReturnErrOption

func WithTranslateData

func WithTranslateData(data ...any) ReturnErrOption

func WithUpdate added in v2.6.1

func WithUpdate(enabled bool, client bot.Client) ReturnErrOption

Jump to

Keyboard shortcuts

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