Initial commit
Signed-off-by: Sayan Biswas <sayan@pokurt.me>
This commit is contained in:
commit
c78090ff6e
|
@ -0,0 +1 @@
|
|||
spb.conf
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="ASK" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/SpamProtection-Mirror-Bot.iml" filepath="$PROJECT_DIR$/.idea/SpamProtection-Mirror-Bot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Package",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/main.go"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func BotInit(config *ShiinaConfig) (b *gotgbot.Bot, updater ext.Updater, err error) {
|
||||
b, err = gotgbot.NewBot(config.BotToken, &gotgbot.BotOpts{
|
||||
Client: http.Client{},
|
||||
GetTimeout: gotgbot.DefaultGetTimeout,
|
||||
PostTimeout: gotgbot.DefaultPostTimeout,
|
||||
})
|
||||
if err != nil {
|
||||
SUGARED.Error(fmt.Sprintf("Failed to create new bot due to %s", err.Error()), zap.Error(err))
|
||||
return nil, updater, err
|
||||
}
|
||||
updater = ext.NewUpdater(nil)
|
||||
err = updater.StartPolling(b, &ext.PollingOpts{DropPendingUpdates: config.DropUpdates})
|
||||
if err != nil {
|
||||
SUGARED.Error(fmt.Sprintf("Failed to start polling due to %s", err.Error()), zap.Error(err))
|
||||
}
|
||||
SUGARED.Info(fmt.Sprintf("%s has started | ID: %d", b.Username, b.Id))
|
||||
return b, updater, nil
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
hocon "github.com/go-akka/configuration"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type ShiinaConfig struct {
|
||||
BotToken string
|
||||
DatabaseName string
|
||||
BotAdmins []int64
|
||||
Debug bool
|
||||
DropUpdates bool
|
||||
}
|
||||
|
||||
func NewShiinaConfig() *ShiinaConfig {
|
||||
return &ShiinaConfig{}
|
||||
}
|
||||
|
||||
func (c *ShiinaConfig) ReadFile(path string) error {
|
||||
b, err := ioutil.ReadFile(path) // just pass the file name
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
conf := hocon.ParseString(string(b))
|
||||
// print(conf.String())
|
||||
c.BotToken = conf.GetString("ShiinaConfig.BotToken")
|
||||
c.DatabaseName = conf.GetString("ShiinaConfig.DatabaseName")
|
||||
c.BotAdmins = conf.GetInt64List("ShiinaConfig.BotAdmins")
|
||||
c.Debug = conf.GetBoolean("ShiinaConfig.Debug")
|
||||
c.DropUpdates = conf.GetBoolean("ShiinaConfig.DropUpdates")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ShiinaConfig) GetBotAdmins() []int64 {
|
||||
var d []int64
|
||||
for i := range c.BotAdmins {
|
||||
d = append(d, c.BotAdmins[i])
|
||||
}
|
||||
return d
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
var SUGARED *zap.SugaredLogger
|
||||
|
||||
func InitZapLog(debug bool) *zap.Logger {
|
||||
var config zap.Config
|
||||
if debug {
|
||||
config = zap.NewDevelopmentConfig()
|
||||
} else {
|
||||
config = zap.NewProductionConfig()
|
||||
}
|
||||
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
config.EncoderConfig.TimeKey = "timestamp"
|
||||
config.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
|
||||
logger, _ := config.Build()
|
||||
return logger
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
module gitlab.com/Dank-del/SpamProtection-Mirror-Bot
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.1
|
||||
github.com/go-akka/configuration v0.0.0-20200606091224-a002c0330665
|
||||
go.uber.org/zap v1.19.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ALiwoto/StrongStringGo v1.0.3 // indirect
|
||||
github.com/ALiwoto/mdparser v1.0.5 // indirect
|
||||
github.com/Intellivoid/Intellivoid.SpamProtection-go v1.0.4 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.7.0 // indirect
|
||||
)
|
|
@ -0,0 +1,69 @@
|
|||
github.com/ALiwoto/StrongStringGo v1.0.3 h1:DQHn3sf5BTKlnoe24dIiFeFGoPfCGqmlyGf6e7RNcFU=
|
||||
github.com/ALiwoto/StrongStringGo v1.0.3/go.mod h1:IRcHbxBe809Mt3qA77FmBUrVhRpbRqAAz/WLkreIyzY=
|
||||
github.com/ALiwoto/mdparser v1.0.5 h1:evOeyr+3qrkdGcXPQylg6aexPgkb8hPkymRizx3F538=
|
||||
github.com/ALiwoto/mdparser v1.0.5/go.mod h1:A5uGV5CGVB0sxKgvu1USLbfYLc5UgwYCRrR+TA9LsI0=
|
||||
github.com/Intellivoid/Intellivoid.SpamProtection-go v1.0.4 h1:LleHKDIntSv5TfaxbM4dMfPlcHO4WgCwA3rZNantGoU=
|
||||
github.com/Intellivoid/Intellivoid.SpamProtection-go v1.0.4/go.mod h1:s5hYKuXnzDAzVfDgfrA/OJCmVbfiarsXu6MXVGh5B9A=
|
||||
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.1 h1:TDob1M3ljHPSZQyPFOZ6ZjOfF4GoYtDA+lfTzd+8Yew=
|
||||
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.1/go.mod h1:r815fYWTudnU9JhtsJAxUtuV7QrSgKpChJkfTSMFpfg=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-akka/configuration v0.0.0-20200606091224-a002c0330665 h1:Iz3aEheYgn+//VX7VisgCmF/wW3BMtXCLbvHV4jMQJA=
|
||||
github.com/go-akka/configuration v0.0.0-20200606091224-a002c0330665/go.mod h1:19bUnum2ZAeftfwwLZ/wRe7idyfoW2MfmXO464Hrfbw=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
|
||||
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
|
||||
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -0,0 +1,38 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/ALiwoto/mdparser/mdparser"
|
||||
"github.com/Intellivoid/Intellivoid.SpamProtection-go/spamProtection"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/helpers"
|
||||
)
|
||||
|
||||
func autoBanHandler(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||
chat := ctx.EffectiveChat
|
||||
user := ctx.EffectiveUser
|
||||
data, err := spamProtection.GetInfoByID(user.Id)
|
||||
if err != nil {
|
||||
helpers.SendError(err, ctx, b)
|
||||
return err
|
||||
}
|
||||
if !data.Success {
|
||||
return nil
|
||||
}
|
||||
if data.IsBlacklisted() {
|
||||
_, err := b.BanChatMember(chat.Id, user.Id, nil)
|
||||
if err != nil {
|
||||
// helpers.SendError(err, ctx, b)
|
||||
return err
|
||||
}
|
||||
txt := mdparser.GetUserMention(user.FirstName, user.Id).AppendBold(" was blacklisted and has been banned!").AppendNormal("\n")
|
||||
txt = txt.AppendBold("Reason").AppendNormal(": ").AppendMono(data.Results.Attributes.BlacklistReason)
|
||||
_, err = b.SendMessage(chat.Id, txt.ToString(), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func msgFilter(msg *gotgbot.Message) bool {
|
||||
return msg.From != nil
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers"
|
||||
)
|
||||
|
||||
func LoadHandlers(d *ext.Dispatcher) {
|
||||
startCMD := handlers.NewCommand("start", startHandler)
|
||||
getMeCMD := handlers.NewCommand("fetch", fetchHandler)
|
||||
autoBan := handlers.NewMessage(msgFilter, autoBanHandler)
|
||||
d.AddHandler(startCMD)
|
||||
d.AddHandler(getMeCMD)
|
||||
d.AddHandler(autoBan)
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/ALiwoto/mdparser/mdparser"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
)
|
||||
|
||||
func startHandler(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||
txt := mdparser.GetBold("Hi, I'm " + b.FirstName).AppendNormal("\n\n")
|
||||
txt = txt.AppendNormal(`I'm a mirror of @SpamProtectionBot, this means`)
|
||||
txt = txt.AppendNormal(` I enforce all bans made through that bot and also provide user information related to it`)
|
||||
_, err := b.SendMessage(ctx.Message.Chat.Id, txt.ToString(), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
|
||||
return err
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ALiwoto/mdparser/mdparser"
|
||||
"github.com/Intellivoid/Intellivoid.SpamProtection-go/spamProtection"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/core"
|
||||
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/helpers"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func fetchHandler(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||
chat := ctx.EffectiveChat
|
||||
var data *spamProtection.APIResponse
|
||||
UserID, err := helpers.GetID(ctx)
|
||||
if err != nil {
|
||||
data, err = spamProtection.GetInfoByUsername(ctx.Args()[1])
|
||||
if err != nil {
|
||||
helpers.SendError(err, ctx, b)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
data, err = spamProtection.GetInfoByID(UserID)
|
||||
}
|
||||
if err != nil {
|
||||
core.SUGARED.Error(err)
|
||||
}
|
||||
if !data.Success {
|
||||
helpers.SendError(errors.New(data.Error.Message), ctx, b)
|
||||
return nil
|
||||
}
|
||||
//var msg mdparser.WMarkDown
|
||||
var ct string
|
||||
if data.IsUser() {
|
||||
ct = "User"
|
||||
} else {
|
||||
// msg = msg.AppendBold("Chat Information").AppendNormal("\n\n")
|
||||
ct = "Chat"
|
||||
}
|
||||
msg := mdparser.GetBold(fmt.Sprintf("%s Information", ct)).AppendNormal("\n\n")
|
||||
if data.IsVerified() {
|
||||
msg = msg.AppendBold(fmt.Sprintf("✅ This %s's Telegram account is verified by Intellivoid Accounts", ct)).AppendNormal("\n")
|
||||
}
|
||||
if data.IsOperator() {
|
||||
msg = msg.AppendBold(fmt.Sprintf("👮 This %s is an operator who can blacklist users", ct)).AppendNormal("\n")
|
||||
}
|
||||
if data.IsAgent() {
|
||||
msg = msg.AppendBold(fmt.Sprintf("👮 This %s is an agent who actively reports spam automatically", ct)).AppendNormal("\n")
|
||||
}
|
||||
if data.IsBlacklisted() {
|
||||
msg = msg.AppendBold(fmt.Sprintf("⚠ This %s is blacklisted!", ct)).AppendNormal("\n")
|
||||
}
|
||||
if data.IsVerified() || data.IsOperator() || data.IsAgent() || data.IsAgent() || data.IsBlacklisted() {
|
||||
msg = msg.AppendNormal("\n")
|
||||
}
|
||||
user, _ := b.GetChat(UserID)
|
||||
msg = msg.AppendBold("Private ID").AppendNormal(":\n").AppendMono(data.Results.PrivateTelegramID).AppendNormal("\n")
|
||||
if UserID != 0 {
|
||||
msg = msg.AppendBold("User ID").AppendNormal(": ").AppendMono(strconv.FormatInt(UserID, 10)).AppendNormal("\n")
|
||||
msg = msg.AppendBold("First Name").AppendNormal(": ").AppendMono(user.FirstName).AppendNormal("\n")
|
||||
if user.LastName != "" {
|
||||
msg = msg.AppendBold("Last Name").AppendNormal(": ").AppendMono(user.LastName).AppendNormal("\n")
|
||||
}
|
||||
if user.Username != "" {
|
||||
msg = msg.AppendBold("Username").AppendNormal(": ").AppendMono(user.Username).AppendNormal("\n")
|
||||
}
|
||||
}
|
||||
if r := data.Results.SpamPrediction; r != nil {
|
||||
msg = msg.AppendBold("Spam Prediction").AppendNormal(": ").AppendMono(fmt.Sprintf("%f", r.SpamPrediction)).AppendNormal("\n")
|
||||
msg = msg.AppendBold("Ham Prediction").AppendNormal(": ").AppendMono(fmt.Sprintf("%f", r.HamPrediction)).AppendNormal("\n")
|
||||
}
|
||||
if l := data.Results.LanguagePrediction; l != nil {
|
||||
msg = msg.AppendBold("Language").AppendNormal(": ").AppendMono(fmt.Sprintf("%s (%f)", l.Language, l.Probability)).AppendNormal("\n")
|
||||
}
|
||||
if UserID != 0 {
|
||||
msg = msg.AppendBold("Permalink").AppendNormal(": ").AppendMention("here", UserID)
|
||||
}
|
||||
_, err = b.SendMessage(chat.Id, msg.ToString(), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/ALiwoto/mdparser/mdparser"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/core"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SendError(err error, ctx *ext.Context, b *gotgbot.Bot) {
|
||||
msg := mdparser.GetBold("Error: ").AppendItalic(err.Error())
|
||||
_, er := b.SendMessage(ctx.EffectiveChat.Id, strings.ReplaceAll(msg.ToString(), b.Token, "token"), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
|
||||
if er != nil {
|
||||
core.SUGARED.Error(err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/PaulSonOfLars/gotgbot/v2/ext"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetID(ctx *ext.Context) (int64, error) {
|
||||
msg := ctx.Message
|
||||
args := ctx.Args()
|
||||
if len(args) == 1 {
|
||||
if msg.ReplyToMessage != nil {
|
||||
return msg.ReplyToMessage.From.Id, nil
|
||||
} else {
|
||||
return msg.From.Id, nil
|
||||
}
|
||||
} else {
|
||||
r, err := strconv.ParseInt(args[1], 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/handlers"
|
||||
"go.uber.org/zap"
|
||||
"log"
|
||||
|
||||
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/core"
|
||||
)
|
||||
|
||||
func main() {
|
||||
e := core.NewShiinaConfig()
|
||||
err := e.ReadFile("spb.conf")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
loggerMgr := core.InitZapLog(e.Debug)
|
||||
zap.ReplaceGlobals(loggerMgr)
|
||||
defer func(loggerMgr *zap.Logger) {
|
||||
err := loggerMgr.Sync()
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
}(loggerMgr) // flushes buffer, if any
|
||||
logger := loggerMgr.Sugar()
|
||||
core.SUGARED = loggerMgr.Sugar()
|
||||
b, up, err := core.BotInit(e)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
handlers.LoadHandlers(up.Dispatcher)
|
||||
logger.Info(b.FirstName, " has started, ID: ", b.Id)
|
||||
up.Idle()
|
||||
}
|
Loading…
Reference in New Issue