Skip to content

Commit

Permalink
Fix quoted warn filters
Browse files Browse the repository at this point in the history
Signed-off-by: ATechnoHazard <[email protected]>
  • Loading branch information
ATechnoHazard committed Jun 19, 2019
1 parent 78bfd6e commit 92b2340
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go_bot/modules/sql/feds_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ChatF struct {
}

type BansF struct {
FedId string `sql:",pk"`
FedId string `sql:",pk" pg:"fk:fed_id"`
UserId string `sql:",pk"`
Reason string
}
Expand Down
2 changes: 2 additions & 0 deletions go_bot/modules/sql/users_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ type ChatMembers struct {
}

func EnsureBotInDb(u *gotgbot.Updater) {
// Create tables if they don't exist
models := []interface{}{&Users{}, &Chats{}, &ChatMembers{}, &Warns{}, &WarnFilters{}, &WarnSettings{}, &BlackListFilters{},
&Federations{}, &ChatF{}, &BansF{}}
for _, model := range models {
err := SESSION.CreateTable(model, &orm.CreateTableOptions{FKConstraints: true})
if err != nil {
// Log errors if they aren't related to already existing tables
if !strings.HasSuffix(err.Error(), "already exists") {
error_handling.HandleErr(err)
}
Expand Down
15 changes: 7 additions & 8 deletions go_bot/modules/utils/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ func SplitMessage(msg string) []string {
}

func SplitQuotes(text string) []string {
SMART_OPEN := "“"
SMART_CLOSE := "”"
START_CHAR := []string{"'", `"`, SMART_OPEN}
smartOpen := "“"
smartClose := "”"
startChars := []string{"'", `"`, smartOpen}
broke := false

for _, char := range START_CHAR {
for _, char := range startChars {
if strings.HasPrefix(text, char) {
counter := 1
for counter < len(text) {
if text[counter] == '\\' {
counter++
} else if text[counter] == text[0] || (string(text[0]) == SMART_OPEN && string(text[counter]) == SMART_CLOSE) {
} else if text[counter] == text[0] || (string(text[0]) == smartOpen && string(text[counter]) == smartClose) {
broke = true
break
}
Expand All @@ -65,11 +65,10 @@ func SplitQuotes(text string) []string {
tmp := make([]string, 2)
tmp[0] = key
tmp[1] = rest
} else {
return strings.SplitN(text, " ", 2)
return tmp
}
}
return make([]string, 0)
return strings.SplitN(text, " ", 2)
}

func RemoveEscapes(text string) string {
Expand Down

0 comments on commit 92b2340

Please sign in to comment.