meido

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 14 Imported by: 0

README

Meido Logo

Meido

Go Report Card Go Reference

A multi-purpose Discord Bot

Invite Meido to your server!

Support server

Features

Meido contains several features that can be useful for running a server, as well as fun commands.

Features include:

  • Moderation
    • Ban / Unban
    • Filter and warns
    • Lockdowns
  • Userroles
  • Youtube and Google image search
  • Utilities
    • Avatar
    • Server info
    • User info
    • Color lookup
  • Media conversion
  • Fishing for the boomer inside you

The feature list will increase as time goes. Some ideas for more features include:

  • Raid protection (will be added)
  • More media conversion such as webm to mp4
  • Gambling
  • XP and level system (maybe, as there are already tons of other bots with this feature)
  • Autoroles
  • Logging

Ideas for other features are more than welcome!

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 BotRecover added in v0.1.1

func BotRecover(i interface{})

BotRecover

func Clamp

func Clamp(lower, upper, n int) int

Clamp clamps a number between a lower and upper limit. Convenience function.

func IDToTimestamp

func IDToTimestamp(idStr string) time.Time

IDToTimestamp converts a discord ID to a timestamp

func Max

func Max(a, b int) int

Max returns the maximum of two numbers. Convenience function.

func Min

func Min(a, b int) int

Min returns the minimum of two numbers. Convenience function.

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 NewBot

func NewBot(config *Config) *Bot

NewBot takes in a Config and returns a pointer to a new Bot

func (*Bot) Close

func (b *Bot) Close()

Close saves all mod states and closes the bot sessions.

func (*Bot) Open

func (b *Bot) Open() error

Open sets up the required things the bot needs to run. establishes a PSQL connection and starts listening for commands.

func (*Bot) RegisterMod

func (b *Bot) RegisterMod(mod Mod)

RegisterMod takes in a Mod and registers it.

func (*Bot) Run

func (b *Bot) Run() error

Run will start the sessions against Discord and runs 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

type CooldownCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func NewDiscord(token string) *Discord

NewDiscord takes in a token and creates a Discord object.

func (*Discord) Channel

func (d *Discord) Channel(channelID string) (*discordgo.Channel, error)

Channel takes in an ID and returns a discordgo.Channel if one with that ID exists.

func (*Discord) Close

func (d *Discord) Close()

Close closes the Discord sessions

func (*Discord) Guild

func (d *Discord) Guild(guildID string) (*discordgo.Guild, error)

Guild takes in an ID and returns a discordgo.Guild if one with that ID exists.

func (*Discord) Guilds

func (d *Discord) Guilds() []*discordgo.Guild

Guilds returns all the guild objects the bot has in its sessions.

func (*Discord) HasPermissions

func (d *Discord) HasPermissions(channelID string, perm int) bool

HasPermissions finds if the bot user has permissions in a channel.

func (*Discord) HighestColor

func (d *Discord) HighestColor(gid, uid string) int

HighestColor finds the role color for the top-most role where the color is non-zero.

func (*Discord) HighestRole

func (d *Discord) HighestRole(gid, uid string) *discordgo.Role

HighestRole finds the highest role a user has in the guild hierarchy.

func (*Discord) HighestRolePosition

func (d *Discord) HighestRolePosition(gid, uid string) int

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

func (d *Discord) Member(guildID, userID string) (*discordgo.Member, error)

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

func (d *Discord) Role(guildID, roleID string) (*discordgo.Role, error)

Role takes in a guild ID and a role ID and returns a discordgo.Role if one with such IDs exists.

func (*Discord) Run

func (d *Discord) Run() error

Run opens the Discord sessions.

func (*Discord) StartTyping

func (d *Discord) StartTyping(channelID string) error

StartTyping makes the bot show as 'typing..' in a channel.

func (*Discord) UserChannelPermissions

func (d *Discord) UserChannelPermissions(userID, channelID string) (int, error)

UserChannelPermissions finds member permissions the usual way, using just the IDs.

func (*Discord) UserChannelPermissionsDirect

func (d *Discord) UserChannelPermissionsDirect(m *discordgo.Member, channelID string) (apermissions int, err error)

UserChannelPermissionsDirect finds permissions based on the *discordgo.Member object directly

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

func (m *DiscordMessage) HasPermissions(mem *discordgo.Member, channelID string, perm int) bool

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

type PermissionCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PermissionCache is yet to be used.

type PermissionSetting

type PermissionSetting struct {
}

PermissionSetting is yet to be used.

type RoleByPos

type RoleByPos []*discordgo.Role

RoleByPos is used to sort discordgo.Roles so that it accurately represents how the hierarchy looks.

func (RoleByPos) Len

func (a RoleByPos) Len() int

func (RoleByPos) Less

func (a RoleByPos) Less(i, j int) bool

func (RoleByPos) Swap

func (a RoleByPos) Swap(i, j int)

Jump to

Keyboard shortcuts

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