More details in ban log message
This commit is contained in:
72
buny.go
72
buny.go
@@ -86,7 +86,16 @@ func bunyPresense(v xmpp.Presence) error { //nolint:gocognit,gocyclo
|
|||||||
log.Debugf("Checking jid %s vs global blacklist regex %s", evilJid, jidRegexp)
|
log.Debugf("Checking jid %s vs global blacklist regex %s", evilJid, jidRegexp)
|
||||||
|
|
||||||
if re.MatchString(evilJid) {
|
if re.MatchString(evilJid) {
|
||||||
if id, err := squash(room, evilJid, room+"/"+evilNick, bEntry.ReasonEnable, v.Type); err != nil {
|
log.Warnf(
|
||||||
|
"Hammer falls on %s (%s): jid matches with global blacklist entry: %s",
|
||||||
|
v.From,
|
||||||
|
evilJid,
|
||||||
|
jidRegexp,
|
||||||
|
)
|
||||||
|
|
||||||
|
id, err := squash(room, evilJid, bEntry.ReasonEnable, v.Type)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"unable to ban user: id=%s, err=%w",
|
"unable to ban user: id=%s, err=%w",
|
||||||
id,
|
id,
|
||||||
@@ -116,8 +125,17 @@ func bunyPresense(v xmpp.Presence) error { //nolint:gocognit,gocyclo
|
|||||||
log.Debugf("Checking nick %s vs global blacklist regex %s", evilNick, nickRegexp)
|
log.Debugf("Checking nick %s vs global blacklist regex %s", evilNick, nickRegexp)
|
||||||
|
|
||||||
if re.MatchString(evilNick) {
|
if re.MatchString(evilNick) {
|
||||||
|
log.Warnf(
|
||||||
|
"Hammer falls on %s (%s): nick matches with global blacklist entry: %s",
|
||||||
|
v.From,
|
||||||
|
evilJid,
|
||||||
|
nickRegexp,
|
||||||
|
)
|
||||||
|
|
||||||
// Баним именно jid
|
// Баним именно jid
|
||||||
if id, err := squash(room, evilJid, room+"/"+evilNick, bEntry.ReasonEnable, v.Type); err != nil {
|
id, err := squash(room, evilJid, bEntry.ReasonEnable, v.Type)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"unable to ban user: id=%s, err=%w",
|
"unable to ban user: id=%s, err=%w",
|
||||||
id,
|
id,
|
||||||
@@ -152,7 +170,16 @@ func bunyPresense(v xmpp.Presence) error { //nolint:gocognit,gocyclo
|
|||||||
log.Debugf("Checking jid %s vs room %s blacklist regex %s", evilJid, room, jidRegexp)
|
log.Debugf("Checking jid %s vs room %s blacklist regex %s", evilJid, room, jidRegexp)
|
||||||
|
|
||||||
if re.MatchString(evilJid) {
|
if re.MatchString(evilJid) {
|
||||||
if id, err := squash(room, evilJid, room+"/"+evilNick, bEntry.ReasonEnable, v.Type); err != nil {
|
log.Warnf(
|
||||||
|
"Hammer falls on %s (%s): jid matches with room blacklist entry: %s",
|
||||||
|
v.From,
|
||||||
|
evilJid,
|
||||||
|
jidRegexp,
|
||||||
|
)
|
||||||
|
|
||||||
|
id, err := squash(room, evilJid, bEntry.ReasonEnable, v.Type)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"unable to ban user: id=%s, err=%w",
|
"unable to ban user: id=%s, err=%w",
|
||||||
id,
|
id,
|
||||||
@@ -183,8 +210,17 @@ func bunyPresense(v xmpp.Presence) error { //nolint:gocognit,gocyclo
|
|||||||
log.Debugf("Checking nick %s vs room %s blacklist regex %s", evilJid, room, nickRegexp)
|
log.Debugf("Checking nick %s vs room %s blacklist regex %s", evilJid, room, nickRegexp)
|
||||||
|
|
||||||
if re.MatchString(evilNick) {
|
if re.MatchString(evilNick) {
|
||||||
|
log.Warnf(
|
||||||
|
"Hammer falls on %s (%s): nick matches with room blacklist entry: %s",
|
||||||
|
v.From,
|
||||||
|
evilJid,
|
||||||
|
nickRegexp,
|
||||||
|
)
|
||||||
|
|
||||||
// Баним именно jid
|
// Баним именно jid
|
||||||
if id, err := squash(room, evilJid, room+"/"+evilNick, bEntry.ReasonEnable, v.Type); err != nil {
|
id, err := squash(room, evilJid, bEntry.ReasonEnable, v.Type)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"unable to ban user: id=%s, err=%w",
|
"unable to ban user: id=%s, err=%w",
|
||||||
id,
|
id,
|
||||||
@@ -239,7 +275,17 @@ func bunyChat(v xmpp.Chat) error {
|
|||||||
log.Debugf("Checking phrase %s vs room %s blacklist regex %s", v.Text, room, phraseRegexp)
|
log.Debugf("Checking phrase %s vs room %s blacklist regex %s", v.Text, room, phraseRegexp)
|
||||||
|
|
||||||
if re.MatchString(v.Text) {
|
if re.MatchString(v.Text) {
|
||||||
if id, err := squash(room, getRealJIDfromNick(v.Remote), v.Remote, bEntry.ReasonEnable, v.Type); err != nil {
|
realJID := getRealJIDfromNick(v.Remote)
|
||||||
|
|
||||||
|
log.Warnf(
|
||||||
|
"Hammer falls on %s (%s): phrase matches with global blacklist entry: %s vs %s",
|
||||||
|
v.Remote,
|
||||||
|
realJID,
|
||||||
|
v.Text,
|
||||||
|
phraseRegexp,
|
||||||
|
)
|
||||||
|
|
||||||
|
if id, err := squash(room, realJID, bEntry.ReasonEnable, v.Type); err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"unable to ban user: id=%s, err=%w",
|
"unable to ban user: id=%s, err=%w",
|
||||||
id,
|
id,
|
||||||
@@ -272,7 +318,17 @@ func bunyChat(v xmpp.Chat) error {
|
|||||||
log.Debugf("Checking phrase %s vs room %s blacklist regex %s", v.Text, room, phraseRegexp)
|
log.Debugf("Checking phrase %s vs room %s blacklist regex %s", v.Text, room, phraseRegexp)
|
||||||
|
|
||||||
if re.MatchString(v.Text) {
|
if re.MatchString(v.Text) {
|
||||||
if id, err := squash(room, getRealJIDfromNick(v.Remote), v.Remote, bEntry.ReasonEnable, v.Type); err != nil {
|
realJID := getRealJIDfromNick(v.Remote)
|
||||||
|
|
||||||
|
log.Warnf(
|
||||||
|
"Hammer falls on %s (%s): phrase matches with room blacklist entry: %s vs %s",
|
||||||
|
v.Remote,
|
||||||
|
realJID,
|
||||||
|
v.Text,
|
||||||
|
phraseRegexp,
|
||||||
|
)
|
||||||
|
|
||||||
|
if id, err := squash(room, realJID, bEntry.ReasonEnable, v.Type); err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"unable to ban user: id=%s, err=%w",
|
"unable to ban user: id=%s, err=%w",
|
||||||
id,
|
id,
|
||||||
@@ -298,14 +354,12 @@ func bunyChat(v xmpp.Chat) error {
|
|||||||
// squash банит указанный jid в указанной комнате.
|
// squash банит указанный jid в указанной комнате.
|
||||||
// reasonEnable указывает, надо ли писать дату автобана в банлисте в поле reason (это единственная причина, в которую
|
// reasonEnable указывает, надо ли писать дату автобана в банлисте в поле reason (это единственная причина, в которую
|
||||||
// умеет бот).
|
// умеет бот).
|
||||||
func squash(room, jid string, nick string, reasonEnable bool, vType string) (string, error) {
|
func squash(room, jid string, reasonEnable bool, vType string) (string, error) {
|
||||||
var (
|
var (
|
||||||
id string
|
id string
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Warnf("Hammer falls on %s(%s)", nick, jid)
|
|
||||||
|
|
||||||
if config.Jabber.BanPhrasesEnable {
|
if config.Jabber.BanPhrasesEnable {
|
||||||
phrase := randomPhrase(config.Jabber.BanPhrases)
|
phrase := randomPhrase(config.Jabber.BanPhrases)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user