new db, add groups feature

This commit is contained in:
Horscchtey 2021-12-02 18:59:46 +00:00
commit f3ed0fe6c0
3 changed files with 33 additions and 15 deletions

View file

@ -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)