From 2cd84df2babb751c2e8bc8e279bee8cfa3c4464b Mon Sep 17 00:00:00 2001 From: Jonas Rabenstein Date: Sat, 25 Jan 2025 00:23:42 +0100 Subject: [PATCH] go fmt --- boddle.go | 27 ++++++++++++++------------- bot.go | 15 +++++++-------- helpers.go | 2 +- logging.go | 8 ++++---- types.go | 20 ++++++++++---------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/boddle.go b/boddle.go index 371087b..899e030 100644 --- a/boddle.go +++ b/boddle.go @@ -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 { @@ -98,10 +99,10 @@ func filter(msg string, conn net.Conn, db *sql.DB, nickname string) cmd { func getRandomEntry(c cmd) string { // TODO: increment counter // if database entry exists: set tag / group and run query - task := "select distinct l.content from line l, brain b, tag t" + 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) diff --git a/bot.go b/bot.go index ada099c..57047c2 100644 --- a/bot.go +++ b/bot.go @@ -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 = "" diff --git a/helpers.go b/helpers.go index f59c740..ca0d985 100644 --- a/helpers.go +++ b/helpers.go @@ -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 diff --git a/logging.go b/logging.go index 6c03744..960763a 100644 --- a/logging.go +++ b/logging.go @@ -6,9 +6,9 @@ import ( ) var ( - LOG_WARN *log.Logger - LOG_INFO *log.Logger - LOG_ERR *log.Logger + LOG_WARN *log.Logger + LOG_INFO *log.Logger + LOG_ERR *log.Logger ) func LOG_init() { @@ -16,5 +16,5 @@ func LOG_init() { LOG_INFO = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) LOG_WARN = log.New(file, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile) - LOG_ERR = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) + LOG_ERR = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) } diff --git a/types.go b/types.go index abfcb0f..3830a6e 100644 --- a/types.go +++ b/types.go @@ -1,17 +1,17 @@ package main type irc_msg struct { - channel string - msg string - author string - retmsg string + channel string + msg string + author string + retmsg string } type cmd struct { - valid bool - add bool - cmd string - groups []string - suffix string - error string + valid bool + add bool + cmd string + groups []string + suffix string + error string }