diff --git a/boddle.db b/boddle.db index a1d5c34..345a363 100644 Binary files a/boddle.db and b/boddle.db differ diff --git a/boddle.go b/boddle.go index 11bd36d..86604cf 100644 --- a/boddle.go +++ b/boddle.go @@ -202,6 +202,35 @@ func parsemsg(msg irc_msg, foo bot) bool { if c.cmd == "help" { return false } + // hard code 'groups' to add new groups to the groups-table + if c.add && (c.cmd == "groups" || c.cmd == "group") { + if (c.groups != nil) { + sendmsg(foo.conn, msg.channel, "Ignoring groups for the groups-adding. Well, what were you expecting...?") + } + new_groups := strings.Fields(c.suffix) + stat_sel, err := db.Prepare("select id from groups where name = ?") + checkErr(err) + stat_ins, err := db.Prepare("insert into groups(name) values (?)") + checkErr(err) + var groups_added []string + for _, group := range new_groups { + fmt.Println(group) + ret, err := stat_sel.Query(group) + if ret.Next() { + ret.Close() + continue + } + _, err = stat_ins.Exec(group) + checkErr(err) + groups_added = append(groups_added, group) + } + if len(groups_added) > 0 { + sendmsg(foo.conn, msg.channel, "Added " + strings.Join(groups_added, ", ") + " to groups-table!") + } else { + sendmsg(foo.conn, msg.channel, "Added nothing to groups-table! :(") + } + return false + } sorter_row, err := db.Query(fmt.Sprintf("select id, tag_id, groups_allow, name_allow, has_groups from sorter where name = '%s'", c.cmd)) checkErr(err) @@ -254,6 +283,7 @@ func parsemsg(msg irc_msg, foo bot) bool { } if c.add { + // if there is nothing to add, just return. :-) if (len(c.suffix) <= 0) { return false; } @@ -265,21 +295,6 @@ func parsemsg(msg irc_msg, foo bot) bool { LOG_WARN.Printf("added line to table.\n") // get ID of content... - /* - task := fmt.Sprintf("select l.id from line l where l.content = \"%s\"", c.suffix) // strings.Replace(c.suffix, "'", "''", -1)) - fmt.Printf(task) - row, err := db.Query(task) - checkErr(err) - line_id := 0 - if row.Next() { row.Scan(&line_id) } - row.Close() - LOG_WARN.Printf(c.cmd) - if line_id == 0 { - LOG_WARN.Printf("no entry for adding") - sendmsg(foo.conn, msg.channel, "internal server error.") - return false - } - */ line_id, err := res.LastInsertId(); checkErr(err) diff --git a/boddle.toml b/boddle.toml new file mode 100644 index 0000000..b4e89af --- /dev/null +++ b/boddle.toml @@ -0,0 +1,3 @@ +name="boddle_dev" +channels=["#horscchtey"] +server="irc.fau.de:6667"