go fmt
This commit is contained in:
parent
41c1c27b1f
commit
2cd84df2ba
5 changed files with 36 additions and 36 deletions
25
boddle.go
25
boddle.go
|
|
@ -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 {
|
||||||
|
|
@ -101,7 +102,7 @@ func getRandomEntry(c cmd) string {
|
||||||
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
|
task += " where l.id = b.line_id and t.id = b.tag_id and t.id = " + c.cmd
|
||||||
if len(c.groups) > 0 {
|
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"
|
task += " ORDER BY RANDOM() LIMIT 1"
|
||||||
return task
|
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 = ?")
|
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,10 +309,10 @@ 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))
|
||||||
} else {
|
} else {
|
||||||
chooseEntry(db, msg, &c)
|
chooseEntry(db, msg, &c)
|
||||||
|
|
|
||||||
15
bot.go
15
bot.go
|
|
@ -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) {
|
||||||
|
|
@ -18,7 +17,7 @@ func sendmsg(conn net.Conn, channel string, msg string) {
|
||||||
conn.Write([]byte(mesg))
|
conn.Write([]byte(mesg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanline_privmsg (msg string, irc *irc_msg) {
|
func scanline_privmsg(msg string, irc *irc_msg) {
|
||||||
LOG_ERR.Printf(msg)
|
LOG_ERR.Printf(msg)
|
||||||
|
|
||||||
msg = msg[1:]
|
msg = msg[1:]
|
||||||
|
|
@ -30,7 +29,7 @@ func scanline_privmsg (msg string, irc *irc_msg) {
|
||||||
(*irc).channel, (*irc).msg = t[0], t[1]
|
(*irc).channel, (*irc).msg = t[0], t[1]
|
||||||
t = strings.Split((*irc).msg, "\r\n")
|
t = strings.Split((*irc).msg, "\r\n")
|
||||||
(*irc).msg = strings.TrimSpace(t[0])
|
(*irc).msg = strings.TrimSpace(t[0])
|
||||||
if ! strings.HasPrefix((*irc).channel, "#") {
|
if !strings.HasPrefix((*irc).channel, "#") {
|
||||||
(*irc).channel = (*irc).author
|
(*irc).channel = (*irc).author
|
||||||
}
|
}
|
||||||
(*irc).retmsg = ""
|
(*irc).retmsg = ""
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
for _, x := range arr {
|
||||||
if x == a {
|
if x == a {
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue