mux

package
v0.0.0-...-eae27d5 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: BSD-3-Clause Imports: 25 Imported by: 0

README

dgMux

Discord Gophers

dgMux is a simple Discord message route multiplexer that parses a message and then executes a matching registered handler. dgMux can be used with Disgord or the DiscordGo library.

If you would like to help the Disgord or DiscordGo package please use this link to add the official DiscordGo test bot dgo to your server. This provides indispensable help to this project.

For help with this program or general Go discussion, please join the Discord Gophers chat server.

NOTE : This is an experimental package and it's likely to have large changes breaking it's API and compatibility with previous versions.

The goal with dgMux is to create a fairly straight forward and simple "command router" that can be added to any DiscordGo bot without much fuss. A secondary goal is to keep the route handlers as close to native DiscordGo handlers as possible. So that each example provided can be used by those just learning the DiscordGo API and easily integrated into their own projects.

Some inspiration was taken from the chi and httprouter routers when creating dgMux.

Documentation

Overview

Package mux provides a simple Discord message route multiplexer that parses messages and then executes a matching registered handler, if found. mux can be used with both Disgord and the DiscordGo library.

Index

Constants

This section is empty.

Variables

View Source
var EmbedsToUpdate = []EmbedToUpdate{}
View Source
var MembersTLChannel = "776620304888889374"
View Source
var PublicTLChannel = "796526853442895915"
View Source
var Pushpin = "\U0001F4CC"
View Source
var ThumbsUp = "\U0001F44D"
View Source
var Triangle = "\U0001F53A"

Functions

func AddMessageToText

func AddMessageToText(message *discordgo.Message, text *string)

func EightHourRange

func EightHourRange(t time.Time) string

func GetAccessSymbol

func GetAccessSymbol(access int) string

func GetEditor

func GetEditor(ds *discordgo.Session, dm *discordgo.Message) func(msg string) *discordgo.Message

func GetResponder

func GetResponder(ds *discordgo.Session, dm *discordgo.Message) func(msg string) *discordgo.Message

func HasAccess

func HasAccess(ds *discordgo.Session, dm *discordgo.MessageCreate, access int) bool

HasAccess check if a user has the specified access level

func ImageCopyEmbeds

func ImageCopyEmbeds(ds *discordgo.Session, msg *discordgo.Message) []*discordgo.MessageEmbed

func IsModerator

func IsModerator(ds *discordgo.Session, dm *discordgo.MessageCreate) bool

IsModerator check if a user is a moderator

func IsStaff

func IsStaff(ds *discordgo.Session, guildID, userID string) bool

IsStaff check if a user is a staff member

func NumLength

func NumLength(in int) int

func PadString

func PadString(str string, length int) string

func RemoveUnwantedElements

func RemoveUnwantedElements(text string) (string, bool)

func StartCopyEmbed

func StartCopyEmbed(cp config.CopyPipeline) *discordgo.MessageEmbed

func StickyEmbed

func StickyEmbed(sticky models.Sticky) *discordgo.MessageEmbed

func StreamsEmbed

func StreamsEmbed(mans []ManualStream, recs []models.YoutubeStreamRecord) *discordgo.MessageEmbed

func TimeBefore

func TimeBefore(t time.Time) string

Types

type Context

type Context struct {
	Fields          []string
	Content         string
	IsDirected      bool
	IsPrivate       bool
	HasPrefix       bool
	HasMention      bool
	HasMentionFirst bool
}

Context holds a bit of extra data we pass along to route handlers This way processing some of this only needs to happen once.

type EmbedToUpdate

type EmbedToUpdate struct {
	ChannelID string
	MessageID string
	Time      time.Time
}

type HandlerFunc

type HandlerFunc func(*discordgo.Session, *discordgo.Message, *Context)

HandlerFunc is the function signature required for a message route handler.

type ManualStream

type ManualStream struct {
	Time          time.Time `json:"time" bson:"time"`
	Title         string    `json:"title" bson:"title"`
	GuerrillaTime string    `json:"guerrilla_time" bson:"guerrilla_time"`
}

func (*ManualStream) ReplacedBy

func (ms *ManualStream) ReplacedBy(recs []models.YoutubeStreamRecord) bool

type MessageLog

type MessageLog struct {
	ChannelName     string
	UserName        string
	Content         string
	OriginalContent string                         `bson:"originalContent,omitempty"`
	Attachments     []*discordgo.MessageAttachment `bson:"attachments,omitempty"`
	MessageID       string
	Action          string
	Time            time.Time
}

type Mux

type Mux struct {
	Routes  []*Route
	Default *Route
	Prefix  string
}

Mux is the main struct for all mux methods.

func New

func New() *Mux

New returns a new Discord message route mux

func (*Mux) AddGuerrilla

func (m *Mux) AddGuerrilla(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) AddReaction

func (m *Mux) AddReaction(ds *discordgo.Session, ra *discordgo.MessageReactionAdd)

func (*Mux) AddStream

func (m *Mux) AddStream(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) AlphaRole

func (m *Mux) AlphaRole(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Avatar

func (m *Mux) Avatar(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) CancelExtraction

func (m *Mux) CancelExtraction(ds *discordgo.Session, e config.Extraction)

func (*Mux) CancelTweetUpdate

func (m *Mux) CancelTweetUpdate(ds *discordgo.Session, tu config.TweetUpdate)

func (*Mux) ClearUntil

func (m *Mux) ClearUntil(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Config

func (m *Mux) Config(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) ConfirmTweet

func (m *Mux) ConfirmTweet(ds *discordgo.Session, st models.SyncedTweet)

func (*Mux) CopyMessageToYoutube

func (m *Mux) CopyMessageToYoutube(ds *discordgo.Session, dm *discordgo.Message, cp config.CopyPipeline)

func (*Mux) CountMembers

func (m *Mux) CountMembers(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) DoClear

func (m *Mux) DoClear(ds *discordgo.Session, channelID string, deleteMessageIDs []string)

func (*Mux) DoExtraction

func (m *Mux) DoExtraction(ds *discordgo.Session, e config.Extraction)

func (*Mux) DoTweetUpdate

func (m *Mux) DoTweetUpdate(ds *discordgo.Session, tu config.TweetUpdate)

func (*Mux) DoTweetUpdateByReply

func (m *Mux) DoTweetUpdateByReply(ds *discordgo.Session, dm *discordgo.Message, ref *discordgo.MessageReference)

func (*Mux) DoubleTL

func (m *Mux) DoubleTL(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) EightBall

func (m *Mux) EightBall(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) EndYoutubeCopy

func (m *Mux) EndYoutubeCopy(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) EnsureSticky

func (m *Mux) EnsureSticky(db *mgo.Database, ds *discordgo.Session, dm *discordgo.Message) bool

func (*Mux) ExtractMessages

func (m *Mux) ExtractMessages(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) FanboxRole

func (m *Mux) FanboxRole(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) FormerRole

func (m *Mux) FormerRole(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) FuzzyMatch

func (m *Mux) FuzzyMatch(msg string) (*Route, []string)

FuzzyMatch attempts to find the best route match for a given message.

func (*Mux) Headpat

func (m *Mux) Headpat(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Help

func (m *Mux) Help(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

Help function provides a build in "help" command that will display a list of all registered routes (commands). To use this function it must first be registered with the Mux.Route function.

func (*Mux) InitScanForUpdates

func (m *Mux) InitScanForUpdates(ds *discordgo.Session)

func (*Mux) LogMessageCreate

func (m *Mux) LogMessageCreate(db *mgo.Database, ds *discordgo.Session, mc *discordgo.MessageCreate, channelName *string)

func (*Mux) Mods

func (m *Mux) Mods(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) MuteRole

func (m *Mux) MuteRole(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Nickname

func (m *Mux) Nickname(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) OnMessageCreate

func (m *Mux) OnMessageCreate(ds *discordgo.Session, mc *discordgo.MessageCreate)

OnMessageCreate is a DiscordGo Event Handler function. This must be registered using the DiscordGo.Session.AddHandler function. This function will receive all Discord messages and parse them for matches to registered routes.

func (*Mux) OnMessageDelete

func (m *Mux) OnMessageDelete(ds *discordgo.Session, md *discordgo.MessageDelete)

func (*Mux) OnMessageDeleteBulk

func (m *Mux) OnMessageDeleteBulk(ds *discordgo.Session, mdb *discordgo.MessageDeleteBulk)

func (*Mux) OnMessageUpdate

func (m *Mux) OnMessageUpdate(ds *discordgo.Session, mu *discordgo.MessageUpdate)

func (*Mux) PromoteMembers

func (m *Mux) PromoteMembers(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Proposal

func (m *Mux) Proposal(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) RefreshConfig

func (m *Mux) RefreshConfig(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) RemoveReaction

func (m *Mux) RemoveReaction(ds *discordgo.Session, rr *discordgo.MessageReactionRemove)

func (*Mux) RemoveStream

func (m *Mux) RemoveStream(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) RoleGrant

func (m *Mux) RoleGrant(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) RoleRemove

func (m *Mux) RoleRemove(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Route

func (m *Mux) Route(pattern, desc string, cb HandlerFunc, access int) (*Route, error)

Route allows you to register a route

func (*Mux) ScanForUpdates

func (m *Mux) ScanForUpdates(ds *discordgo.Session)

func (*Mux) SpecialRole

func (m *Mux) SpecialRole(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Sticky

func (m *Mux) Sticky(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Stream

func (m *Mux) Stream(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Streams

func (m *Mux) Streams(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) SyncSheet

func (m *Mux) SyncSheet(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) TestMsg

func (m *Mux) TestMsg(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) TestSync

func (m *Mux) TestSync(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Translate

func (m *Mux) Translate(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) TweetEdit

func (m *Mux) TweetEdit(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) TweetTranslate

func (m *Mux) TweetTranslate(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Unsticky

func (m *Mux) Unsticky(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) UpdateProposal

func (m *Mux) UpdateProposal(ds *discordgo.Session, guildID, channelID, messageID string)

func (*Mux) VDebug

func (m *Mux) VDebug(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) Verify

func (m *Mux) Verify(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) VerifyFormer

func (m *Mux) VerifyFormer(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) WhaleRole

func (m *Mux) WhaleRole(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

func (*Mux) YoutubeCopy

func (m *Mux) YoutubeCopy(ds *discordgo.Session, dm *discordgo.Message, ctx *Context)

type Route

type Route struct {
	Pattern     string      // match pattern that should trigger this route handler
	Description string      // short description of this route
	Help        string      // detailed help string for this route
	Run         HandlerFunc // route handler function to call
	Access      int         // access level for the command
}

Route holds information about a specific message route handler

Jump to

Keyboard shortcuts

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