From 8757f7c6aafae316785d9c84075e5d16fcaf0689 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Wed, 25 Jul 2018 12:59:22 +0200 Subject: [PATCH] Plugins in plugin folder --- .drone.yml | 2 ++ build_plugins.sh | 12 ++++++++++++ plugin.go => plugin/plugin.go | 2 +- test.go => plugin/test.go | 0 test2.go => plugin/test2.go | 0 plugin_manager/context.go | 9 --------- plugin_manager/manager.go | 8 ++++---- 7 files changed, 19 insertions(+), 14 deletions(-) create mode 100755 build_plugins.sh rename plugin.go => plugin/plugin.go (98%) rename test.go => plugin/test.go (100%) rename test2.go => plugin/test2.go (100%) delete mode 100644 plugin_manager/context.go diff --git a/.drone.yml b/.drone.yml index 6758f2c..00c8502 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,6 +3,7 @@ pipeline: image: golang group: build commands: + - sh build_plugins.sh - go get -v -d ./... - go build . test: @@ -11,6 +12,7 @@ pipeline: secrets: [ test_api_token ] environment: [ test_api_token ] commands: + - sh build_plugins.sh - go get -v -d ./... - go test ./... publish: diff --git a/build_plugins.sh b/build_plugins.sh new file mode 100755 index 0000000..cfc47b8 --- /dev/null +++ b/build_plugins.sh @@ -0,0 +1,12 @@ +# @Author: Bartuccio Antoine +# @Date: 2018-07-25 12:47:23 +# @Last Modified by: klmp200 +# @Last Modified time: 2018-07-25 12:58:04 +#!/bin/sh +cd plugin +rm -f *.so +FILES=`ls *.go` +for FILE in $FILES +do + go build -buildmode=plugin $FILE +done \ No newline at end of file diff --git a/plugin.go b/plugin/plugin.go similarity index 98% rename from plugin.go rename to plugin/plugin.go index 0408dac..14c2637 100644 --- a/plugin.go +++ b/plugin/plugin.go @@ -1,7 +1,7 @@ package main import ( - "./plugin_manager" + "../plugin_manager" tb "gopkg.in/tucnak/telebot.v2" ) diff --git a/test.go b/plugin/test.go similarity index 100% rename from test.go rename to plugin/test.go diff --git a/test2.go b/plugin/test2.go similarity index 100% rename from test2.go rename to plugin/test2.go diff --git a/plugin_manager/context.go b/plugin_manager/context.go deleted file mode 100644 index fa34617..0000000 --- a/plugin_manager/context.go +++ /dev/null @@ -1,9 +0,0 @@ -package plugin_manager - -import ( - tb "gopkg.in/tucnak/telebot.v2" -) - -type Context struct { - bot *tb.Bot -} diff --git a/plugin_manager/manager.go b/plugin_manager/manager.go index 919a7ae..d4371ae 100644 --- a/plugin_manager/manager.go +++ b/plugin_manager/manager.go @@ -21,13 +21,13 @@ type PluginCtrl struct { var pluginDir string var pluginsRunning bool var plugins map[string]PluginCtrl -var context Context +var context *tb.Bot func Init(_pluginDir string, bot *tb.Bot) { pluginDir = _pluginDir pluginsRunning = false plugins = make(map[string]PluginCtrl) - context.bot = bot + context = bot for _, fileName := range GetSoFiles(pluginDir) { var p PluginCtrl p.plugin = LoadSoFile(pluginDir + "/" + fileName) @@ -111,10 +111,10 @@ func HandleMessage(msg *tb.Message) { split := strings.Split(msg.Text, " ") split[0] = split[0][1:] if Contains(split[0], ExecGetCommands(val.plugin)) { - ExecHandleCommand(val.plugin, context.bot, msg, split[0], split[1:]) + ExecHandleCommand(val.plugin, context, msg, split[0], split[1:]) } } else { - ExecHandleMessage(val.plugin, context.bot, msg) + ExecHandleMessage(val.plugin, context, msg) } } }