mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add additional banphrases
This commit is contained in:
parent
b990375d9b
commit
9820b957ac
|
@ -13,9 +13,9 @@ import (
|
||||||
"github.com/jakecoffman/cron"
|
"github.com/jakecoffman/cron"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
"github.com/nicklaw5/helix/v2"
|
||||||
"github.com/nouryxd/nourybot/internal/data"
|
"github.com/nouryxd/nourybot/internal/data"
|
||||||
"github.com/nouryxd/nourybot/pkg/common"
|
"github.com/nouryxd/nourybot/pkg/common"
|
||||||
"github.com/nicklaw5/helix/v2"
|
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v4"
|
"github.com/gempir/go-twitch-irc/v4"
|
||||||
|
@ -38,6 +39,18 @@ var (
|
||||||
// More information:
|
// More information:
|
||||||
// https://gist.github.com/pajlada/57464e519ba8d195a97ddcd0755f9715
|
// https://gist.github.com/pajlada/57464e519ba8d195a97ddcd0755f9715
|
||||||
func (app *application) checkMessage(text string) (bool, string) {
|
func (app *application) checkMessage(text string) (bool, string) {
|
||||||
|
pattern := `\bi(?:'|\s?a)?m\s?(?:\d|1[0-2])(?:\s?year|$)`
|
||||||
|
|
||||||
|
re, err := regexp.Compile(pattern)
|
||||||
|
if err != nil {
|
||||||
|
app.Log.Error("Error compiling regular expression:", err)
|
||||||
|
return true, "could not check regex"
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.MatchString(text) {
|
||||||
|
return true, "regex matched"
|
||||||
|
}
|
||||||
|
|
||||||
// {"message": "AHAHAHAHA LUL"}
|
// {"message": "AHAHAHAHA LUL"}
|
||||||
reqBody, err := json.Marshal(map[string]string{
|
reqBody, err := json.Marshal(map[string]string{
|
||||||
"message": text,
|
"message": text,
|
||||||
|
@ -83,6 +96,18 @@ func (app *application) checkMessage(text string) (bool, string) {
|
||||||
|
|
||||||
// SendNoContext is used to send twitch replies without the full twitch.PrivateMessage context to be logged.
|
// SendNoContext is used to send twitch replies without the full twitch.PrivateMessage context to be logged.
|
||||||
func (app *application) SendNoContext(target, message string) {
|
func (app *application) SendNoContext(target, message string) {
|
||||||
|
pattern := `\bi(?:'|\s?a)?m\s?(?:\d|1[0-2])(?:\s?year|$)`
|
||||||
|
|
||||||
|
re, err := regexp.Compile(pattern)
|
||||||
|
if err != nil {
|
||||||
|
app.Log.Error("Error compiling regular expression:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.MatchString(message) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Message we are trying to send is empty.
|
// Message we are trying to send is empty.
|
||||||
if len(message) == 0 {
|
if len(message) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -142,6 +167,17 @@ func (app *application) SendNoContext(target, message string) {
|
||||||
// Send is used to send twitch replies and contains the necessary safeguards and logic for that.
|
// Send is used to send twitch replies and contains the necessary safeguards and logic for that.
|
||||||
// Send also logs the twitch.PrivateMessage contents into the database.
|
// Send also logs the twitch.PrivateMessage contents into the database.
|
||||||
func (app *application) Send(target, message string, msgContext twitch.PrivateMessage) {
|
func (app *application) Send(target, message string, msgContext twitch.PrivateMessage) {
|
||||||
|
pattern := `\bi(?:'|\s?a)?m\s?(?:\d|1[0-2])(?:\s?year|$)`
|
||||||
|
|
||||||
|
re, err := regexp.Compile(pattern)
|
||||||
|
if err != nil {
|
||||||
|
app.Log.Error("Error compiling regular expression:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.MatchString(message) {
|
||||||
|
return
|
||||||
|
}
|
||||||
// Message we are trying to send is empty.
|
// Message we are trying to send is empty.
|
||||||
if len(message) == 0 {
|
if len(message) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -201,6 +237,18 @@ func (app *application) Send(target, message string, msgContext twitch.PrivateMe
|
||||||
|
|
||||||
// SendNoBanphrase does not check the banphrase before sending a twitch mesage.
|
// SendNoBanphrase does not check the banphrase before sending a twitch mesage.
|
||||||
func (app *application) SendNoBanphrase(target, message string) {
|
func (app *application) SendNoBanphrase(target, message string) {
|
||||||
|
pattern := `\bi(?:'|\s?a)?m\s?(?:\d|1[0-2])(?:\s?year|$)`
|
||||||
|
|
||||||
|
re, err := regexp.Compile(pattern)
|
||||||
|
if err != nil {
|
||||||
|
app.Log.Error("Error compiling regular expression:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.MatchString(message) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Message we are trying to send is empty.
|
// Message we are trying to send is empty.
|
||||||
if len(message) == 0 {
|
if len(message) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -231,6 +279,17 @@ func (app *application) SendNoBanphrase(target, message string) {
|
||||||
// Used in sending commands from the database since the command has to have
|
// Used in sending commands from the database since the command has to have
|
||||||
// been gotten in there somehow. So it fits. Still checks for banphrases.
|
// been gotten in there somehow. So it fits. Still checks for banphrases.
|
||||||
func (app *application) SendNoLimit(target, message string) {
|
func (app *application) SendNoLimit(target, message string) {
|
||||||
|
pattern := `\bi(?:'|\s?a)?m\s?(?:\d|1[0-2])(?:\s?year|$)`
|
||||||
|
|
||||||
|
re, err := regexp.Compile(pattern)
|
||||||
|
if err != nil {
|
||||||
|
app.Log.Error("Error compiling regular expression:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if re.MatchString(message) {
|
||||||
|
return
|
||||||
|
}
|
||||||
// Message we are trying to send is empty.
|
// Message we are trying to send is empty.
|
||||||
if len(message) == 0 {
|
if len(message) == 0 {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue