Documentation
¶
Index ¶
- Variables
- func BotRecover(i interface{})
- func Clamp(lower, upper, n int) int
- func IDToTimestamp(idStr string) time.Time
- func Max(a, b int) int
- func Min(a, b int) int
- type Bot
- type Config
- type CooldownCache
- type Discord
- func (d *Discord) Channel(channelID string) (*discordgo.Channel, error)
- func (d *Discord) Close()
- func (d *Discord) Guild(guildID string) (*discordgo.Guild, error)
- func (d *Discord) Guilds() []*discordgo.Guild
- func (d *Discord) HasPermissions(channelID string, perm int) bool
- func (d *Discord) HighestColor(gid, uid string) int
- func (d *Discord) HighestRole(gid, uid string) *discordgo.Role
- func (d *Discord) HighestRolePosition(gid, uid string) int
- func (d *Discord) IsOwner(msg *DiscordMessage) bool
- func (d *Discord) Member(guildID, userID string) (*discordgo.Member, error)
- func (d *Discord) Open() (<-chan *DiscordMessage, error)
- func (d *Discord) Role(guildID, roleID string) (*discordgo.Role, error)
- func (d *Discord) Run() error
- func (d *Discord) StartTyping(channelID string) error
- func (d *Discord) UserChannelPermissions(userID, channelID string) (int, error)
- func (d *Discord) UserChannelPermissionsDirect(m *discordgo.Member, channelID string) (apermissions int, err error)
- type DiscordMessage
- func (m *DiscordMessage) Args() []string
- func (m *DiscordMessage) HasPermissions(mem *discordgo.Member, channelID string, perm int) bool
- func (m *DiscordMessage) IsDM() bool
- func (m *DiscordMessage) IsOwner() bool
- func (m *DiscordMessage) LenArgs() int
- func (m *DiscordMessage) RawArgs() []string
- func (m *DiscordMessage) RawContent() string
- func (m *DiscordMessage) Reply(data string) (*discordgo.Message, error)
- func (m *DiscordMessage) ReplyEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)
- type ExecutedCommand
- type MessageType
- type Mod
- type ModCommand
- type ModPassive
- type PermissionCache
- type PermissionSetting
- type RoleByPos
Constants ¶
This section is empty.
Variables ¶
var PermMap = map[int]string{ 0: "None", discordgo.PermissionCreateInstantInvite: "Create Instant Invite", discordgo.PermissionKickMembers: "Kick Members", discordgo.PermissionBanMembers: "Ban Members", discordgo.PermissionAdministrator: "Administrator", discordgo.PermissionManageChannels: "Manage Channels", discordgo.PermissionManageServer: "Manage Server", discordgo.PermissionAddReactions: "Add Reactions", discordgo.PermissionViewAuditLogs: "View Audit Log", discordgo.PermissionVoicePrioritySpeaker: "Priority Speaker", discordgo.PermissionViewChannel: "View Channel", discordgo.PermissionSendMessages: "Send Messages", discordgo.PermissionSendTTSMessages: "Send TTS Messages", discordgo.PermissionManageMessages: "Manage Messages", discordgo.PermissionEmbedLinks: "Embed Links", discordgo.PermissionAttachFiles: "Attach Files", discordgo.PermissionReadMessageHistory: "Read Message History", discordgo.PermissionMentionEveryone: "Mention Everyone", discordgo.PermissionUseExternalEmojis: "Use External Emojis", discordgo.PermissionVoiceConnect: "Connect", discordgo.PermissionVoiceSpeak: "Speak", discordgo.PermissionVoiceMuteMembers: "Mute Members", discordgo.PermissionVoiceDeafenMembers: "Deafen Members", discordgo.PermissionVoiceMoveMembers: "Move Members", discordgo.PermissionVoiceUseVAD: "Use VAD", discordgo.PermissionChangeNickname: "Change Nickname", discordgo.PermissionManageNicknames: "Manage Nicknames", discordgo.PermissionManageRoles: "Manage Roles", discordgo.PermissionManageWebhooks: "Manage Webhooks", discordgo.PermissionManageEmojis: "Manage Emojis", }
PermMap is a map that simply converts specific permission bits to the readable version of what they represent.
Functions ¶
func IDToTimestamp ¶
IDToTimestamp converts a discord ID to a timestamp
Types ¶
type Bot ¶
type Bot struct { Discord *Discord Config *Config Mods map[string]Mod CommandLog chan *ExecutedCommand DB *sqlx.DB Owo *owo.Client Cooldowns CooldownCache }
Bot is the main bot struct.
func (*Bot) Open ¶
Open sets up the required things the bot needs to run. establishes a PSQL connection and starts listening for commands.
func (*Bot) RegisterMod ¶
RegisterMod takes in a Mod and registers it.
type Config ¶
type Config struct { Token string `json:"token"` OwoToken string `json:"owo_token"` ConnectionString string `json:"connection_string"` DmLogChannels []string `json:"dm_log_channels"` OwnerIds []string `json:"owner_ids"` YouTubeKey string `json:"youtube_key"` }
Config is the config struct for the bot.
type CooldownCache ¶
CooldownCache is a collection of command cooldowns.
type Discord ¶
type Discord struct { Sess *discordgo.Session Sessions []*discordgo.Session // contains filtered or unexported fields }
Discord represents the part of the bot that deals with interaction with Discord.
func NewDiscord ¶
NewDiscord takes in a token and creates a Discord object.
func (*Discord) Channel ¶
Channel takes in an ID and returns a discordgo.Channel if one with that ID exists.
func (*Discord) Guild ¶
Guild takes in an ID and returns a discordgo.Guild if one with that ID exists.
func (*Discord) HasPermissions ¶
HasPermissions finds if the bot user has permissions in a channel.
func (*Discord) HighestColor ¶
HighestColor finds the role color for the top-most role where the color is non-zero.
func (*Discord) HighestRole ¶
HighestRole finds the highest role a user has in the guild hierarchy.
func (*Discord) HighestRolePosition ¶
HighestRolePosition gets the highest role position a user has in the guild hierarchy.
func (*Discord) IsOwner ¶
func (d *Discord) IsOwner(msg *DiscordMessage) bool
IsOwner returns whether the author of a DiscordMessage is a bot owner by checking the IDs in the ownerIDs in the Discord struct.
func (*Discord) Member ¶
Member takes in a guild ID and a user ID and returns a discordgo.Member if one with such ID exists.
func (*Discord) Open ¶
func (d *Discord) Open() (<-chan *DiscordMessage, error)
Open populates the Discord object with Sessions and returns a DiscordMessage channel.
func (*Discord) Role ¶
Role takes in a guild ID and a role ID and returns a discordgo.Role if one with such IDs exists.
func (*Discord) StartTyping ¶
StartTyping makes the bot show as 'typing..' in a channel.
func (*Discord) UserChannelPermissions ¶
UserChannelPermissions finds member permissions the usual way, using just the IDs.
type DiscordMessage ¶
type DiscordMessage struct { Sess *discordgo.Session Discord *Discord Message *discordgo.Message // Partial guild member, use only for guild related stuff Author *discordgo.User Member *discordgo.Member Type MessageType TimeReceived time.Time Shard int }
DiscordMessage represents a Discord message sent in a channel, and contains fields so that it is easy to work with the data it gives.
func (*DiscordMessage) Args ¶
func (m *DiscordMessage) Args() []string
Args returns the split content of a DiscordMessage in lowercase.
func (*DiscordMessage) HasPermissions ¶
HasPermissions returns if a member has certain permissions or not.
func (*DiscordMessage) IsDM ¶
func (m *DiscordMessage) IsDM() bool
IsDM returns whether or not the message is a direct message.
func (*DiscordMessage) IsOwner ¶
func (m *DiscordMessage) IsOwner() bool
IsOwner returns whether the author of the message is a bot owner.
func (*DiscordMessage) LenArgs ¶
func (m *DiscordMessage) LenArgs() int
LenArgs returns the length of Args
func (*DiscordMessage) RawArgs ¶
func (m *DiscordMessage) RawArgs() []string
RawArgs returns the raw split content of a DiscordMessage.
func (*DiscordMessage) RawContent ¶
func (m *DiscordMessage) RawContent() string
RawContent returns the raw content of a DiscordMessage.
func (*DiscordMessage) Reply ¶
func (m *DiscordMessage) Reply(data string) (*discordgo.Message, error)
Reply replies directly to a DiscordMessage
func (*DiscordMessage) ReplyEmbed ¶
func (m *DiscordMessage) ReplyEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)
ReplyEmbed replies directly to a DiscordMessage with an embed.
type ExecutedCommand ¶
type ExecutedCommand struct { Msg *DiscordMessage Cmd *ModCommand }
ExecutedCommand is a struct that contains the data of a successfully executed command.
type MessageType ¶
type MessageType int
MessageType represents the 3 types of message events from Discord.
const ( MessageTypeCreate MessageType = 1 << iota MessageTypeUpdate MessageTypeDelete )
MessageType codes.
type Mod ¶
type Mod interface { Name() string Save() error Load() error Passives() []*ModPassive Commands() map[string]*ModCommand AllowedTypes() MessageType AllowDMs() bool Hook(*Bot) error RegisterCommand(*ModCommand) }
Mod represents a collection of commands and passives.
type ModCommand ¶
type ModCommand struct { Mod Mod Name string Description string Triggers []string Usage string Cooldown int CooldownUser bool RequiredPerms int RequiresOwner bool CheckBotPerms bool AllowedTypes MessageType AllowDMs bool Enabled bool Run func(*DiscordMessage) `json:"-"` }
ModCommand represents a command for a Mod.
type ModPassive ¶
type ModPassive struct { Mod Mod Name string Description string AllowedTypes MessageType Enabled bool Run func(*DiscordMessage) `json:"-"` }
ModPassive represents a passive for a Mod.
type PermissionCache ¶
PermissionCache is yet to be used.