now with config files
This commit is contained in:
parent
f37e55173a
commit
844578f217
6 changed files with 71 additions and 86 deletions
94
boddle.go
94
boddle.go
|
|
@ -27,6 +27,7 @@ var err error
|
|||
|
||||
func checkErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Printf("::::ERROR:::: %s\n", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -193,12 +194,12 @@ func parsemsg(msg irc_msg, foo bot) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
LOG_WARN.Printf("line was parsed, continue with evaluation.\n")
|
||||
if c.cmd == "" {
|
||||
LOG_WARN.Printf("no command provided.\n")
|
||||
return false
|
||||
}
|
||||
if c.cmd == "pepe" && msg.author == "spaghetto" {
|
||||
printPepe(msg.author, foo)
|
||||
if c.cmd == "help" {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -211,6 +212,7 @@ func parsemsg(msg irc_msg, foo bot) bool {
|
|||
var name_allow int
|
||||
var has_groups int
|
||||
sorter_row.Scan(&sorter_id, &tag_id, &groups_allow, &name_allow, &has_groups)
|
||||
sorter_row.Close()
|
||||
|
||||
if groups_allow != 0 {
|
||||
sendmsg(foo.conn, msg.channel, "This command does not allow groups. :(")
|
||||
|
|
@ -218,38 +220,32 @@ func parsemsg(msg irc_msg, foo bot) bool {
|
|||
}
|
||||
if name_allow != 0 && !c.add {
|
||||
// warning: not allowed
|
||||
sendmsg(foo.conn, msg.channel, "This command ignores provided names. :(")
|
||||
c.suffix = ""
|
||||
}
|
||||
|
||||
c.cmd = tag_id
|
||||
|
||||
var sorter_groups []string
|
||||
if has_groups == 0 {
|
||||
sorter_groups_row, err := 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
|
||||
sorter_groups_row.Scan(&group_id)
|
||||
if c.add {
|
||||
sorter_groups = append(sorter_groups, fmt.Sprintf("%d", group_id))
|
||||
} else {
|
||||
c.groups = append(c.groups, fmt.Sprintf("%d", group_id))
|
||||
}
|
||||
c.groups = append(c.groups, fmt.Sprintf("%d", group_id))
|
||||
}
|
||||
sorter_groups_row.Close()
|
||||
}
|
||||
sorter_row.Close()
|
||||
if c.add {
|
||||
var tag_name string
|
||||
tag_name_row, err := db.Query(fmt.Sprintf("select name from tag where id = %d", tag_id))
|
||||
checkErr(err)
|
||||
if tag_name_row.Next() {
|
||||
tag_name_row.Scan(&tag_name)
|
||||
if c.add {
|
||||
var tag_name string
|
||||
tag_name_row, err := db.Query(fmt.Sprintf("select name from tag where id = %d", tag_id))
|
||||
checkErr(err)
|
||||
if tag_name_row.Next() {
|
||||
tag_name_row.Scan(&tag_name)
|
||||
}
|
||||
tag_name_row.Close()
|
||||
LOG_WARN.Printf("Alias used. Tell the user about that.\n")
|
||||
sendmsg(foo.conn, msg.channel, "You're using an alias. Please try again with 'add " + tag_name + " [" + strings.Join(c.groups, " ") + "]. Thanks!")
|
||||
return false
|
||||
}
|
||||
tag_name_row.Close()
|
||||
sendmsg(foo.conn, msg.channel, "You're using an alias. Please try again with 'add" + tag_name + " [" + strings.Join(sorter_groups, " ") + "]. Thanks!")
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
LOG_WARN.Printf("no sorter entry, no translation possible\n")
|
||||
|
|
@ -262,15 +258,14 @@ func parsemsg(msg irc_msg, foo bot) bool {
|
|||
return false;
|
||||
}
|
||||
c.suffix = strings.Replace(c.suffix,"\"","'", -1)
|
||||
fmt.Printf(c.suffix)
|
||||
// insert into database
|
||||
statement, err := db.Prepare("insert into line (content, author) values (?,?)")
|
||||
LOG_WARN.Printf("adding new stuff: %s from %s.\n", c.suffix, msg.author)
|
||||
|
||||
res, err := db.Exec("insert into line (content, author) values (?,?)", c.suffix, msg.author)
|
||||
checkErr(err)
|
||||
_, err = statement.Exec(c.suffix, msg.author)
|
||||
checkErr(err)
|
||||
defer statement.Close()
|
||||
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)
|
||||
|
|
@ -278,13 +273,17 @@ func parsemsg(msg irc_msg, foo bot) bool {
|
|||
line_id := 0
|
||||
if row.Next() { row.Scan(&line_id) }
|
||||
row.Close()
|
||||
LOG_INFO.Printf(c.cmd)
|
||||
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)
|
||||
|
||||
LOG_WARN.Printf("line_id: %d, tag_id: %d, groups: %s\n", line_id, c.cmd, strings.Join(c.groups, "-"))
|
||||
// for tag and all groups
|
||||
if len(c.groups) == 0 {
|
||||
stat, err := db.Prepare("insert into brain(line_id, tag_id) values (?,?)")
|
||||
|
|
@ -329,44 +328,3 @@ func parsemsg(msg irc_msg, foo bot) bool {
|
|||
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
func test() {
|
||||
db, err = sql.Open("sqlite3", "./boddle.db")
|
||||
checkErr(err)
|
||||
var msg irc_msg
|
||||
msg.channel = "testchannel"
|
||||
msg.author = "max mustermann"
|
||||
|
||||
// == invalid commands ==
|
||||
// empty cmd
|
||||
msg.msg = ">add [test me bro hahahaha] blob"
|
||||
parsemsg(msg)
|
||||
msg.msg = "> [test me bro hahahaha]"
|
||||
parsemsg(msg)
|
||||
msg.msg = ">[test me bro hahahaha] meow "
|
||||
parsemsg(msg)
|
||||
msg.msg = ">add [test me bro hahahaha] meow "
|
||||
parsemsg(msg)
|
||||
|
||||
// non-existent groups
|
||||
msg.msg = ">ohai [test me bro hahahaha]"
|
||||
parsemsg(msg)
|
||||
|
||||
// add command...? not implemented yet!
|
||||
msg.msg = ">add jokes blob"
|
||||
parsemsg(msg)
|
||||
msg.msg = ">add test [test me bro hahahaha] meow "
|
||||
parsemsg(msg)
|
||||
|
||||
// ok command \o/
|
||||
msg.msg = ">flirt [sweet] meow "
|
||||
parsemsg(msg)
|
||||
msg.msg = ">jokes [flach] meow "
|
||||
parsemsg(msg)
|
||||
msg.msg = ">hate [sweet] blobfisch "
|
||||
parsemsg(msg)
|
||||
msg.msg = ">radschlag [science]"
|
||||
parsemsg(msg)
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue