Discord Components & Role Selection (#5)
This commit is contained in:
		@ -31,7 +31,7 @@ type Bot struct {
 | 
			
		||||
	onEventUpdatedHandlers   [](func(common.Event) error)
 | 
			
		||||
	onEventCompletedHandlers [](func(common.Event) error)
 | 
			
		||||
 | 
			
		||||
	gameModules []common.GameModule
 | 
			
		||||
	gameModules []common.ChatSyncModule
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Initalize creates the discord session and registers handlers
 | 
			
		||||
@ -62,6 +62,11 @@ func (app *Bot) Initialize(cfg *core.Config) error {
 | 
			
		||||
	app.Session.OnEventDelete(app.onEventDelete)
 | 
			
		||||
	app.Session.OnEventUpdate(app.onEventUpdate)
 | 
			
		||||
 | 
			
		||||
	btn := app.Session.NewButton("test", "Click Me")
 | 
			
		||||
	btn.OnClick(func(user common.User) {
 | 
			
		||||
		print("clicked")
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ func NewComponentLoader(bot *Bot) *ComponentLoader {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (loader *ComponentLoader) LoadComponent(component common.Component) {
 | 
			
		||||
func (loader *ComponentLoader) LoadComponent(component common.Module) {
 | 
			
		||||
	if err := component.Initialize(loader); err != nil {
 | 
			
		||||
		log.Print("Failed to load component: ", err)
 | 
			
		||||
	}
 | 
			
		||||
@ -50,7 +50,7 @@ func (loader *ComponentLoader) OnEventComplete(handler func(common.Event) error)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (loader *ComponentLoader) RegisterGameModule(ID string, plugin common.GameModule) error {
 | 
			
		||||
func (loader *ComponentLoader) RegisterChatSyncModule(ID string, plugin common.ChatSyncModule) error {
 | 
			
		||||
	return fmt.Errorf("unimplemented")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// LoadPlugin loads a plugin and returns its component if successful
 | 
			
		||||
func LoadPlugin(pluginPath string) common.Component {
 | 
			
		||||
func LoadPlugin(pluginPath string) common.Module {
 | 
			
		||||
 | 
			
		||||
	plug, err := plugin.Open(pluginPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@ -25,8 +25,8 @@ func LoadPlugin(pluginPath string) common.Component {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Validate component type
 | 
			
		||||
	var component common.Component
 | 
			
		||||
	component, ok := sym.(common.Component)
 | 
			
		||||
	var component common.Module
 | 
			
		||||
	component, ok := sym.(common.Module)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		log.Printf("Failed to load plugin '%s': Plugin component does not properly implement interface!", pluginPath)
 | 
			
		||||
	}
 | 
			
		||||
@ -35,15 +35,15 @@ func LoadPlugin(pluginPath string) common.Component {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LoadPlugins loads all plugins and componenets in a directory
 | 
			
		||||
func LoadPlugins(directory string) []common.Component {
 | 
			
		||||
func LoadPlugins(directory string) []common.Module {
 | 
			
		||||
 | 
			
		||||
	paths, err := os.ReadDir(directory)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("Failed to load plugins: %s", err)
 | 
			
		||||
		return []common.Component{}
 | 
			
		||||
		return []common.Module{}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var components []common.Component = make([]common.Component, 0)
 | 
			
		||||
	var components []common.Module = make([]common.Module, 0)
 | 
			
		||||
	for _, path := range paths {
 | 
			
		||||
		if path.IsDir() {
 | 
			
		||||
			continue
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user