forked from ProtobufBot/Go-Mirai-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,6 @@ captcha.jpg | |
cuberbot | ||
tmp | ||
dist/ | ||
plugins/ | ||
plugins/ | ||
gmc_android.aar | ||
gmc_android-sources.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
gomobile bind -target=android ./service/gmc_android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gmc_android | ||
|
||
import ( | ||
"github.com/ProtobufBot/Go-Mirai-Client/pkg/config" | ||
"github.com/ProtobufBot/Go-Mirai-Client/pkg/gmc" | ||
|
||
log "github.com/sirupsen/logrus" | ||
_ "golang.org/x/mobile/bind" | ||
) | ||
|
||
var logger AndroidLogger | ||
|
||
// SetPluginPath 设置插件配置路径 | ||
func SetPluginPath(pluginPath string) { | ||
config.PluginPath = pluginPath | ||
} | ||
|
||
// SetSms 设置是否短信优先 | ||
func SetSms(sms bool) { | ||
config.SMS = sms | ||
} | ||
|
||
// Start 启动主程序 | ||
func Start() { | ||
gmc.Start() | ||
} | ||
|
||
// SetLogger 设置日志输出 | ||
func SetLogger(androidLogger AndroidLogger) { | ||
logger = androidLogger | ||
log.SetOutput(&AndroidWriter{}) | ||
log.SetFormatter(&AndroidFormatter{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gmc_android | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type AndroidLogger interface { | ||
Log(str string) | ||
} | ||
|
||
type AndroidWriter struct { | ||
} | ||
|
||
func (AndroidWriter) Write(p []byte) (n int, err error) { | ||
if logger != nil { | ||
logger.Log(string(p)) | ||
} | ||
return 0, nil | ||
} | ||
|
||
type AndroidFormatter struct { | ||
} | ||
|
||
func (AndroidFormatter) Format(entry *log.Entry) ([]byte, error) { | ||
buf := bytes.Buffer{} | ||
buf.WriteByte('[') | ||
buf.WriteString(entry.Time.Format("2006-01-02 15:04:05")) | ||
buf.WriteString("] [") | ||
buf.WriteString(strings.ToUpper(entry.Level.String())) | ||
buf.WriteString("]: ") | ||
buf.WriteString(entry.Message) | ||
buf.WriteString(" \n") | ||
buf.Bytes() | ||
return append([]byte(nil), buf.Bytes()...), nil | ||
} | ||
|