Implement optional reason in room' banlist
This commit is contained in:
41
buny.go
41
buny.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/eleksir/go-xmpp"
|
"github.com/eleksir/go-xmpp"
|
||||||
@@ -82,7 +83,8 @@ func buny(v xmpp.Presence) error { //nolint:gocognit
|
|||||||
Type: v.Type,
|
Type: v.Type,
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
gTomb.Killf("unable to send phrase to room %s: %w", room, err)
|
err := fmt.Errorf("unable to send phrase to room %s: %w", room, err)
|
||||||
|
gTomb.Kill(err)
|
||||||
|
|
||||||
// Здесь возвращаем nil, т.к. за нас ошибку залоггирует код выше
|
// Здесь возвращаем nil, т.к. за нас ошибку залоггирует код выше
|
||||||
return nil
|
return nil
|
||||||
@@ -91,7 +93,22 @@ func buny(v xmpp.Presence) error { //nolint:gocognit
|
|||||||
|
|
||||||
// https://xmpp.org/extensions/xep-0045.html#ban баним вот таким сообщением
|
// https://xmpp.org/extensions/xep-0045.html#ban баним вот таким сообщением
|
||||||
ban := "<item affiliation='outcast' jid='" + evilJid + "'>"
|
ban := "<item affiliation='outcast' jid='" + evilJid + "'>"
|
||||||
ban += "<reason />"
|
|
||||||
|
if bEntry.ReasonEnable {
|
||||||
|
var t = time.Now()
|
||||||
|
ban += fmt.Sprintf(
|
||||||
|
"<reason>autoban at %04d.%02d.%02d %02d:%02d:%02d</reason>",
|
||||||
|
t.Year(),
|
||||||
|
t.Month(),
|
||||||
|
t.Day(),
|
||||||
|
t.Hour(),
|
||||||
|
t.Minute(),
|
||||||
|
t.Second(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ban += "<reason />"
|
||||||
|
}
|
||||||
|
|
||||||
ban += "</item>"
|
ban += "</item>"
|
||||||
|
|
||||||
if id, err := talk.RawInformationQuery(
|
if id, err := talk.RawInformationQuery(
|
||||||
@@ -144,7 +161,8 @@ func buny(v xmpp.Presence) error { //nolint:gocognit
|
|||||||
Type: v.Type,
|
Type: v.Type,
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
gTomb.Killf("unable to send phrase to room %s: %w", room, err)
|
err := fmt.Errorf("unable to send phrase to room %s: %w", room, err)
|
||||||
|
gTomb.Kill(err)
|
||||||
|
|
||||||
// Здесь возвращаем nil, т.к. за нас ошибку залоггирует код выше
|
// Здесь возвращаем nil, т.к. за нас ошибку залоггирует код выше
|
||||||
return nil
|
return nil
|
||||||
@@ -153,7 +171,22 @@ func buny(v xmpp.Presence) error { //nolint:gocognit
|
|||||||
|
|
||||||
// https://xmpp.org/extensions/xep-0045.html#ban баним вот таким сообщением
|
// https://xmpp.org/extensions/xep-0045.html#ban баним вот таким сообщением
|
||||||
ban := "<item affiliation='outcast' jid='" + evilJid + "'>"
|
ban := "<item affiliation='outcast' jid='" + evilJid + "'>"
|
||||||
ban += "<reason />"
|
|
||||||
|
if bEntry.ReasonEnable {
|
||||||
|
var t = time.Now()
|
||||||
|
ban += fmt.Sprintf(
|
||||||
|
"<reason>autoban at %04d.%02d.%02d %02d:%02d:%02d</reason>",
|
||||||
|
t.Year(),
|
||||||
|
t.Month(),
|
||||||
|
t.Day(),
|
||||||
|
t.Hour(),
|
||||||
|
t.Minute(),
|
||||||
|
t.Second(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ban += "<reason />"
|
||||||
|
}
|
||||||
|
|
||||||
ban += "</item>"
|
ban += "</item>"
|
||||||
|
|
||||||
if id, err := talk.RawInformationQuery(
|
if id, err := talk.RawInformationQuery(
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
{
|
{
|
||||||
# Пустой список означает глобальные баны, которые применяются ко всем комнатам, где присутствует бот
|
# Пустой список означает глобальные баны, которые применяются ко всем комнатам, где присутствует бот
|
||||||
"room_name": "",
|
"room_name": "",
|
||||||
|
# Записывать ли в reason в банлисте комнаты сообщение вида autoban at yyyy.MM.dd hh:mm:ss
|
||||||
|
"reason_enable": false,
|
||||||
# Список регулярок JID-ов, которых надо банить
|
# Список регулярок JID-ов, которых надо банить
|
||||||
"jid_re": [
|
"jid_re": [
|
||||||
"^[Mm]ary@server.tld/resource1$",
|
"^[Mm]ary@server.tld/resource1$",
|
||||||
|
|||||||
5
types.go
5
types.go
@@ -50,8 +50,9 @@ type myWhiteList struct {
|
|||||||
// myBlackList прототип структурки с чёрным списком jid-ов.
|
// myBlackList прототип структурки с чёрным списком jid-ов.
|
||||||
type myBlackList struct {
|
type myBlackList struct {
|
||||||
Blacklist []struct {
|
Blacklist []struct {
|
||||||
RoomName string `json:"room_name,omitempty"`
|
RoomName string `json:"room_name,omitempty"`
|
||||||
JidRe []string `json:"jid_re,omitempty"`
|
ReasonEnable bool `json:"reason_enable,omitempty"`
|
||||||
|
JidRe []string `json:"jid_re,omitempty"`
|
||||||
} `json:"blacklist,omitempty"`
|
} `json:"blacklist,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user