This commit is contained in:
Jonas Rabenstein 2025-01-25 00:23:42 +01:00
commit 2cd84df2ba
5 changed files with 36 additions and 36 deletions

View file

@ -1,12 +1,13 @@
package main package main
import ( import (
"strings"
"fmt"
"regexp"
"database/sql" "database/sql"
"math/rand" "fmt"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"math/rand"
"net"
"regexp"
"strings"
) )
var begin_char = []byte{'-'} var begin_char = []byte{'-'}
@ -31,7 +32,7 @@ func filter(msg string, conn net.Conn, db *sql.DB, nickname string) cmd {
c.add = false c.add = false
} }
if (strings.Contains(msg, "[") && strings.Contains(msg, "]")) { if strings.Contains(msg, "[") && strings.Contains(msg, "]") {
re, _ := regexp.Compile(`\s*(\w*)\s*\[(.+)\]\s*(.*)\s*`) re, _ := regexp.Compile(`\s*(\w*)\s*\[(.+)\]\s*(.*)\s*`)
res := re.FindStringSubmatch(msg) res := re.FindStringSubmatch(msg)
if len(res) < 4 { if len(res) < 4 {
@ -167,7 +168,7 @@ func checkSorter(db *sql.DB, msg *irc_msg, c *cmd) bool {
group_sel, err := db.Prepare("select group_id from sorter_groups where sorter_id = ?") group_sel, err := db.Prepare("select group_id from sorter_groups where sorter_id = ?")
checkErr(err) checkErr(err)
sorter_groups_row, err := group_sel.Query(sorter_id) sorter_groups_row, err := group_sel.Query(sorter_id)
//sorter_groups_row, err := db.Query(fmt.Sprintf("select group_id from sorter_groups where sorter_id = '%s'", sorter_id)) //sorter_groups_row, err := foo.db.Query(fmt.Sprintf("select group_id from sorter_groups where sorter_id = '%s'", sorter_id))
checkErr(err) checkErr(err)
if sorter_groups_row.Next() { if sorter_groups_row.Next() {
var group_id int var group_id int
@ -223,7 +224,7 @@ func addLine(db *sql.DB, msg *irc_msg, line string, groups []string, cmd string)
LOG_WARN.Printf("added line to table.\n") LOG_WARN.Printf("added line to table.\n")
// get ID of content... // get ID of content...
line_id, err := res.LastInsertId(); line_id, err := res.LastInsertId()
checkErr(err) checkErr(err)
LOG_WARN.Printf("line_id: %d, tag_id: %s, groups: %s\n", line_id, cmd, strings.Join(groups, "-")) LOG_WARN.Printf("line_id: %d, tag_id: %s, groups: %s\n", line_id, cmd, strings.Join(groups, "-"))
@ -293,7 +294,7 @@ func parsemsg(msg *irc_msg, conn net.Conn, db *sql.DB, nickname string) bool {
} }
// hard code 'groups' to add new groups to the groups-table // hard code 'groups' to add new groups to the groups-table
if c.add && (c.cmd == "groups" || c.cmd == "group") { if c.add && (c.cmd == "groups" || c.cmd == "group") {
if (c.groups != nil) { if c.groups != nil {
(*msg).retmsg = "Ignoring groups for the groups-adding. Well, what were you expecting...?" (*msg).retmsg = "Ignoring groups for the groups-adding. Well, what were you expecting...?"
} }
addgroups(db, strings.Fields((&c).suffix), msg) addgroups(db, strings.Fields((&c).suffix), msg)
@ -308,8 +309,8 @@ func parsemsg(msg *irc_msg, conn net.Conn, db *sql.DB, nickname string) bool {
// new line for database // new line for database
if c.add { if c.add {
// if there is nothing to add, just return. :-) // if there is nothing to add, just return. :-)
if (len(c.suffix) <= 0) { if len(c.suffix) <= 0 {
return false; return false
} }
c.suffix = strings.Replace(c.suffix, "\"", "'", -1) c.suffix = strings.Replace(c.suffix, "\"", "'", -1)
sendmsg(conn, "horscchtey", addLine(db, msg, c.suffix, c.groups, c.cmd)) sendmsg(conn, "horscchtey", addLine(db, msg, c.suffix, c.groups, c.cmd))

11
bot.go
View file

@ -1,15 +1,14 @@
package main package main
import ( import (
"log"
"fmt"
"net"
"time"
"bufio" "bufio"
"strings"
"database/sql" "database/sql"
configo "github.com/distributedio/configo" "flag"
"fmt"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"net"
"strings"
"time"
) )
func sendmsg(conn net.Conn, channel string, msg string) { func sendmsg(conn net.Conn, channel string, msg string) {