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
import (
"strings"
"fmt"
"regexp"
"database/sql"
"math/rand"
"fmt"
_ "github.com/mattn/go-sqlite3"
"math/rand"
"net"
"regexp"
"strings"
)
var begin_char = []byte{'-'}
@ -31,7 +32,7 @@ func filter(msg string, conn net.Conn, db *sql.DB, nickname string) cmd {
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*`)
res := re.FindStringSubmatch(msg)
if len(res) < 4 {
@ -101,7 +102,7 @@ func getRandomEntry(c cmd) string {
task := "select distinct l.content from line l, brain b, tag t"
task += " where l.id = b.line_id and t.id = b.tag_id and t.id = " + c.cmd
if len(c.groups) > 0 {
task += " and l.id in (select line_id from brain where group_id = " + strings.Join(c.groups," intersect select line_id from brain where group_id = ") + ")"
task += " and l.id in (select line_id from brain where group_id = " + strings.Join(c.groups, " intersect select line_id from brain where group_id = ") + ")"
}
task += " ORDER BY RANDOM() LIMIT 1"
return task
@ -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 = ?")
checkErr(err)
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)
if sorter_groups_row.Next() {
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")
// get ID of content...
line_id, err := res.LastInsertId();
line_id, err := res.LastInsertId()
checkErr(err)
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
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...?"
}
addgroups(db, strings.Fields((&c).suffix), msg)
@ -308,10 +309,10 @@ func parsemsg(msg *irc_msg, conn net.Conn, db *sql.DB, nickname string) bool {
// new line for database
if c.add {
// if there is nothing to add, just return. :-)
if (len(c.suffix) <= 0) {
return false;
if len(c.suffix) <= 0 {
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))
} else {
chooseEntry(db, msg, &c)

15
bot.go
View file

@ -1,15 +1,14 @@
package main
import (
"log"
"fmt"
"net"
"time"
"bufio"
"strings"
"database/sql"
configo "github.com/distributedio/configo"
"flag"
"fmt"
_ "github.com/mattn/go-sqlite3"
"net"
"strings"
"time"
)
func sendmsg(conn net.Conn, channel string, msg string) {
@ -18,7 +17,7 @@ func sendmsg(conn net.Conn, channel string, msg string) {
conn.Write([]byte(mesg))
}
func scanline_privmsg (msg string, irc *irc_msg) {
func scanline_privmsg(msg string, irc *irc_msg) {
LOG_ERR.Printf(msg)
msg = msg[1:]
@ -30,7 +29,7 @@ func scanline_privmsg (msg string, irc *irc_msg) {
(*irc).channel, (*irc).msg = t[0], t[1]
t = strings.Split((*irc).msg, "\r\n")
(*irc).msg = strings.TrimSpace(t[0])
if ! strings.HasPrefix((*irc).channel, "#") {
if !strings.HasPrefix((*irc).channel, "#") {
(*irc).channel = (*irc).author
}
(*irc).retmsg = ""

View file

@ -11,7 +11,7 @@ func checkErr(err error) {
}
}
func in (a byte, arr []byte) bool {
func in(a byte, arr []byte) bool {
for _, x := range arr {
if x == a {
return true