some fixes and changes
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"kurumibot/database/psql"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||
"git.nix13.pw/scuroneko/laniakea/utils"
|
||||
"github.com/vinovest/sqlx"
|
||||
)
|
||||
|
||||
func RegisterAdmin(b *laniakea.Bot) {
|
||||
@@ -14,7 +17,7 @@ func RegisterAdmin(b *laniakea.Bot) {
|
||||
p.Command(uploadPhoto, "uploadPhoto")
|
||||
p.Command(emojiId, "emojiId")
|
||||
p.Command(getProxy, "proxy")
|
||||
p.Command(test, "test")
|
||||
p.Command(execSql, "sql")
|
||||
|
||||
p.AddMiddleware(AdminMiddleware())
|
||||
b.AddPlugins(p.Build())
|
||||
@@ -31,8 +34,32 @@ func AdminMiddleware() *laniakea.PluginMiddleware {
|
||||
return m
|
||||
}
|
||||
|
||||
func test(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.Answer("Ok")
|
||||
func execSql(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
stmt := strings.Join(ctx.Args, " ")
|
||||
stmt = db.PostgresSQL.Rebind(stmt)
|
||||
|
||||
var res []map[string]any
|
||||
r, err := db.PostgresSQL.Query(stmt)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
defer r.Close()
|
||||
for r.Next() {
|
||||
a := make(map[string]any)
|
||||
if err = sqlx.MapScan(r, a); err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
res = append(res, a)
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(res, "", " ")
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
ctx.Answerf("`%s`", data)
|
||||
}
|
||||
func getProxy(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ruProxy := "tg://proxy?port=3128&secret=7qaZyfQN-IQ7ZMwrR_zWnHBvem9uLnJ1&server=185.231.245.25"
|
||||
|
||||
Reference in New Issue
Block a user