Documentation ¶
Overview ¶
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
Copyright (C) 2022-2023 ikafly144
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/>.
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/>.
Copyright (C) 2022-2023 ikafly144
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
- Variables
- func ActivitiesNameString(locale discordgo.Locale, activity *discordgo.Activity) (str string)
- func AddIntegrationHandler[T any](b *BotManager, handler func(*Api, *discordgo.Session, T))
- func ErrorMessageEmbed(i *discordgo.InteractionCreate, t string) []*discordgo.MessageEmbed
- func ErrorRespond(i *discordgo.InteractionCreate, err error) *discordgo.InteractionResponse
- func ErrorTraceEmbed(locale discordgo.Locale, err error) []*discordgo.MessageEmbed
- func MessageLogDetails(m []MessageLog) (day, week, all int, channelID string)
- func RequestFeatureIDRespond(s *discordgo.Session, i *discordgo.InteractionCreate, f *Feature) (ic *discordgo.InteractionCreate, fID []string)
- func SendWebhook(s *discordgo.Session, channelID string, data *discordgo.WebhookParams) (st *discordgo.Message, err error)
- func SetEmbedProperties(embeds []*discordgo.MessageEmbed) []*discordgo.MessageEmbed
- func StatusString(status discordgo.Status) (str string)
- func WaitNewInteractionResponseSingle(s *discordgo.Session, i *discordgo.InteractionCreate, ...) (ic *discordgo.InteractionCreate, err error)
- type Api
- func (a *Api) FeatureDisable(guildID, featureID, id string) (err error)
- func (a *Api) FeatureEnable(guildID, featureID, id string) (err error)
- func (a *Api) FeatureEnabled(guildID, featureID, id string) (enabled bool, err error)
- func (a *Api) Gateway() (gateway string, err error)
- func (a *Api) Request(method, urlStr string, data any) (response []byte, err error)
- func (a *Api) StaticsUserMessage(guildID, userID string) (logs []MessageLog, err error)
- type ApplicationCommand
- type ApplicationCommands
- type BotManager
- func (b *BotManager) AddApiHandler(handler any)
- func (b *BotManager) AddHandler(handler any)
- func (b *BotManager) ApplicationCommandCreate(tree ApplicationCommands) (registeredCommands []*discordgo.ApplicationCommand, err error)
- func (b *BotManager) ApplicationCommandDelete(cmd []*discordgo.ApplicationCommand) (err error)
- func (b *BotManager) ApplicationCommands() ([]*discordgo.ApplicationCommand, error)
- func (b *BotManager) Close() (err error)
- func (bm *BotManager) FeatureApplicationCommandHandler() func(*discordgo.Session, *discordgo.InteractionCreate)
- func (bm *BotManager) FeatureApplicationCommandSettingsSet(settings FeatureApplicationCommandSettings)
- func (bm *BotManager) FeatureCreate(f *Feature) (err error)
- func (bm *BotManager) FeatureHandler() func(*discordgo.Session, any)
- func (bm *BotManager) FeaturesApplicationCommand() *discordgo.ApplicationCommand
- func (b *BotManager) LocalApplicationCommandDelete() error
- func (b *BotManager) Open() (err error)
- type Event
- type EventHandler
- type EventInterfaceProvider
- type Feature
- type FeatureApplicationCommandSettings
- type FeatureData
- type FeatureIDType
- type FeatureManager
- type FeatureType
- type GuildFeature
- type MessageLog
- type RequestConfig
- type Shard
- type StatusUpdate
- type WaitNewInteractionResponseMessageData
Constants ¶
const ( FeatureMessageCreate FeatureType = "MESSAGE_CREATE" FeatureTypingStart = "TYPING_START" FeatureCustom = "CUSTOM" FeatureUnknown FeatureType = "" )
Variables ¶
var ( Endpoint = "http://localhost:8686/" EndpointAPI = Endpoint + "api/v" + APIVersion + "/" EndpointGateway = EndpointAPI + "gateway" EndpointGuild = EndpointAPI + "guild" EndpointMessage = EndpointAPI + "message" EndpointGuildFeature = EndpointGuild + "/feature" EndpointStatics = EndpointAPI + "statics/" EndpointStaticsUser = EndpointStatics + "user" EndpointStaticsUserMessage = EndpointStaticsUser + "/message" )
var APIVersion = "0"
var (
ErrNoFeatureData = errors.New("no feature data")
)
var Features = map[FeatureType]string{ FeatureMessageCreate: "Message Create", FeatureTypingStart: "Typing Start", FeatureCustom: "Custom", FeatureUnknown: "Unknown", }
Functions ¶
func ActivitiesNameString ¶
アクティビティ名をアクティビティの種類によって渡された言語に翻訳して返す
func AddIntegrationHandler ¶
func AddIntegrationHandler[T any](b *BotManager, handler func(*Api, *discordgo.Session, T))
DiscordAPIイベントから内部APIを呼び出すときに使う
XXX: メソッドで実装したい
func ErrorMessageEmbed ¶
func ErrorMessageEmbed(i *discordgo.InteractionCreate, t string) []*discordgo.MessageEmbed
エラーメッセージ埋め込みを作成する
func ErrorRespond ¶
func ErrorRespond(i *discordgo.InteractionCreate, err error) *discordgo.InteractionResponse
エラーが発生したことを返すレスポンスを作成する
func ErrorTraceEmbed ¶
func ErrorTraceEmbed(locale discordgo.Locale, err error) []*discordgo.MessageEmbed
エラートレース埋め込みを作成する
func MessageLogDetails ¶
func MessageLogDetails(m []MessageLog) (day, week, all int, channelID string)
func RequestFeatureIDRespond ¶
func RequestFeatureIDRespond(s *discordgo.Session, i *discordgo.InteractionCreate, f *Feature) (ic *discordgo.InteractionCreate, fID []string)
TODO: 再利用可能に
func SendWebhook ¶
func SetEmbedProperties ¶
func SetEmbedProperties(embeds []*discordgo.MessageEmbed) []*discordgo.MessageEmbed
埋め込みの色、フッター、タイムスタンプを設定する
func WaitNewInteractionResponseSingle ¶
func WaitNewInteractionResponseSingle(s *discordgo.Session, i *discordgo.InteractionCreate, messageData WaitNewInteractionResponseMessageData) (ic *discordgo.InteractionCreate, err error)
TODO: クソみたいな仕様 TODO: 使い方を書き残す TODO: 使わないかもしれない
Types ¶
type Api ¶
type Api struct { sync.RWMutex Client http.Client MaxRestRetries int UserAgent string Dialer *websocket.Dialer // contains filtered or unexported fields }
func (*Api) FeatureDisable ¶
func (*Api) FeatureEnable ¶
func (*Api) FeatureEnabled ¶
func (*Api) Request ¶
内部REST APIに(GET, POST)リクエストを送信する Sequenceはシーケンス回数を指定する。 もし502エラーで失敗したら成功するかシーケンスがapi.MaxRestRetries以上になるまでシーケンス回数+1回繰り返します
func (*Api) StaticsUserMessage ¶
func (a *Api) StaticsUserMessage(guildID, userID string) (logs []MessageLog, err error)
type ApplicationCommand ¶
type ApplicationCommand struct { *discordgo.ApplicationCommand Handler func(*discordgo.Session, *discordgo.InteractionCreate) }
アプリケーションコマンドとそのハンダラを備えた構造体
type ApplicationCommands ¶
type ApplicationCommands []*ApplicationCommand
アプリケーションコマンドのスライス型
func (*ApplicationCommands) Parse ¶
func (a *ApplicationCommands) Parse() func(*discordgo.Session, *discordgo.InteractionCreate)
アプリケーションコマンドを解析してハンダラを返す
type BotManager ¶
type BotManager struct { *Api ShardCount int Shards []*Shard // contains filtered or unexported fields }
ボット接続を管理する
func (*BotManager) AddApiHandler ¶
func (b *BotManager) AddApiHandler(handler any)
内部APIのイベントハンダラを登録する
func (*BotManager) AddHandler ¶
func (b *BotManager) AddHandler(handler any)
セッションにDiscordAPIイベントハンダラを登録する
func (*BotManager) ApplicationCommandCreate ¶
func (b *BotManager) ApplicationCommandCreate(tree ApplicationCommands) (registeredCommands []*discordgo.ApplicationCommand, err error)
ボットにアプリケーションコマンドを登録する
func (*BotManager) ApplicationCommandDelete ¶
func (b *BotManager) ApplicationCommandDelete(cmd []*discordgo.ApplicationCommand) (err error)
ボットからアプリケーションコマンドを削除する
func (*BotManager) ApplicationCommands ¶
func (b *BotManager) ApplicationCommands() ([]*discordgo.ApplicationCommand, error)
ボットに登録されているコマンドを取得する
func (*BotManager) FeatureApplicationCommandHandler ¶
func (bm *BotManager) FeatureApplicationCommandHandler() func(*discordgo.Session, *discordgo.InteractionCreate)
func (*BotManager) FeatureApplicationCommandSettingsSet ¶
func (bm *BotManager) FeatureApplicationCommandSettingsSet(settings FeatureApplicationCommandSettings)
func (*BotManager) FeatureCreate ¶
func (bm *BotManager) FeatureCreate(f *Feature) (err error)
func (*BotManager) FeatureHandler ¶
func (bm *BotManager) FeatureHandler() func(*discordgo.Session, any)
func (*BotManager) FeaturesApplicationCommand ¶
func (bm *BotManager) FeaturesApplicationCommand() *discordgo.ApplicationCommand
func (*BotManager) LocalApplicationCommandDelete ¶
func (b *BotManager) LocalApplicationCommandDelete() error
サポートサーバーからすべてのコマンドを削除する
TODO: 消すか残りも実装するか
type EventHandler ¶
type EventInterfaceProvider ¶
type Feature ¶
type Feature struct { Name string ID string IDType FeatureIDType ChannelTypes []discordgo.ChannelType Type FeatureType Handler any }
type FeatureData ¶
type FeatureIDType ¶
type FeatureIDType string
const ( FeatureChannelID FeatureIDType = "CHANNEL_ID" FeatureUserID FeatureIDType = "USER_ID" FeatureGuildID FeatureIDType = "GUILD_ID" FeatureRoleID FeatureIDType = "ROLE_ID" )
type FeatureManager ¶
type FeatureManager struct { sync.Mutex ApplicationCommandSettings FeatureApplicationCommandSettings // contains filtered or unexported fields }
func NewFeatureManager ¶
func NewFeatureManager() *FeatureManager
type FeatureType ¶
type FeatureType string
func (FeatureType) String ¶
func (f FeatureType) String() string
type GuildFeature ¶
type MessageLog ¶
type RequestConfig ¶
type WaitNewInteractionResponseMessageData ¶
type WaitNewInteractionResponseMessageData struct { Data *discordgo.InteractionResponseData Type discordgo.InteractionResponseType // TypeがInteractionResponseModalの時のみ使用される ModalComponent []discordgo.MessageComponent ModalHandler func(*discordgo.Session, *discordgo.MessageComponentInteractionData) }