toml to parameters
This commit is contained in:
parent
fd022bddfd
commit
41c1c27b1f
4 changed files with 86 additions and 78 deletions
32
boddle.go
32
boddle.go
|
|
@ -10,12 +10,9 @@ import (
|
|||
)
|
||||
|
||||
var begin_char = []byte{'-'}
|
||||
var db *sql.DB
|
||||
var err error
|
||||
|
||||
|
||||
// function to split advise message correctly
|
||||
func filter(msg string, foo bot) cmd {
|
||||
func filter(msg string, conn net.Conn, db *sql.DB, nickname string) cmd {
|
||||
var c cmd
|
||||
|
||||
if len(msg) <= 0 {
|
||||
|
|
@ -66,7 +63,7 @@ func filter(msg string, foo bot) cmd {
|
|||
c.groups = append(c.groups, fmt.Sprintf("%d", group_id))
|
||||
} else {
|
||||
if c.add {
|
||||
c.groups = append(c.groups, addgroups([]string{group}, nil)...)
|
||||
c.groups = append(c.groups, addgroups(db, []string{group}, nil)...)
|
||||
}
|
||||
}
|
||||
rows.Close()
|
||||
|
|
@ -110,7 +107,7 @@ func getRandomEntry(c cmd) string {
|
|||
return task
|
||||
}
|
||||
|
||||
func addgroups(new_groups []string, msg *irc_msg) []string {
|
||||
func addgroups(db *sql.DB, new_groups []string, msg *irc_msg) []string {
|
||||
stat_sel, err := db.Prepare("select id from groups where name = ?")
|
||||
checkErr(err)
|
||||
stat_ins, err := db.Prepare("insert into groups(name) values (?)")
|
||||
|
|
@ -141,7 +138,7 @@ func addgroups(new_groups []string, msg *irc_msg) []string {
|
|||
return groupids_added
|
||||
}
|
||||
|
||||
func checkSorter(msg *irc_msg, c *cmd) bool {
|
||||
func checkSorter(db *sql.DB, msg *irc_msg, c *cmd) bool {
|
||||
sorter_row_sel, err := db.Prepare("select id, tag_id, groups_allow, name_allow, has_groups from sorter where name = ?")
|
||||
checkErr(err)
|
||||
sorter_row, err := sorter_row_sel.Query((*c).cmd)
|
||||
|
|
@ -199,7 +196,7 @@ func checkSorter(msg *irc_msg, c *cmd) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func chooseEntry(msg *irc_msg, c *cmd) {
|
||||
func chooseEntry(db *sql.DB, msg *irc_msg, c *cmd) {
|
||||
task := getRandomEntry(*c)
|
||||
|
||||
LOG_INFO.Printf(task)
|
||||
|
|
@ -218,7 +215,7 @@ func chooseEntry(msg *irc_msg, c *cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
func addLine(msg *irc_msg, line string, groups []string, cmd string) string {
|
||||
func addLine(db *sql.DB, msg *irc_msg, line string, groups []string, cmd string) string {
|
||||
LOG_WARN.Printf("adding new stuff: %s from %s.\n", line, (*msg).author)
|
||||
|
||||
res, err := db.Exec("insert into line (content, author) values (?,?)", line, (*msg).author)
|
||||
|
|
@ -247,12 +244,13 @@ func addLine(msg *irc_msg, line string, groups []string, cmd string) string {
|
|||
defer stat.Close()
|
||||
}
|
||||
(*msg).retmsg = fmt.Sprintf("success adding new super funny enjoyable line with ID %d!", line_id)
|
||||
return fmt.Sprintf("new line: > %s < (ID %d), into groups %s", line, line_id, strings.Join(groups,","))
|
||||
return fmt.Sprintf("new line: > %s < (ID %d), into groups %s", line, line_id, strings.Join(groups, ","))
|
||||
}
|
||||
|
||||
// line:
|
||||
// >befehl <[groups]> <name>
|
||||
// befehl ist genau ein wort
|
||||
func parsemsg(msg *irc_msg, foo bot) bool {
|
||||
func parsemsg(msg *irc_msg, conn net.Conn, db *sql.DB, nickname string) bool {
|
||||
if len((*msg).msg) <= 0 {
|
||||
return false
|
||||
}
|
||||
|
|
@ -265,7 +263,7 @@ func parsemsg(msg *irc_msg, foo bot) bool {
|
|||
}
|
||||
(*msg).msg = (*msg).msg[1:]
|
||||
|
||||
c := filter((*msg).msg, foo)
|
||||
c := filter((*msg).msg, conn, db, nickname)
|
||||
if !c.valid {
|
||||
LOG_WARN.Printf("non valid input found.\n")
|
||||
if c.error != "" {
|
||||
|
|
@ -284,7 +282,7 @@ func parsemsg(msg *irc_msg, foo bot) bool {
|
|||
}
|
||||
if c.cmd == "slap" {
|
||||
who := []string{(*msg).author, "\x01ACTION"}
|
||||
whom := []string{(*msg).author, foo.Conf.Name}
|
||||
whom := []string{(*msg).author, nickname}
|
||||
LOG_WARN.Printf("suffix: " + c.suffix)
|
||||
if c.suffix != "" {
|
||||
who = append(who, strings.Split(c.suffix, " ")...)
|
||||
|
|
@ -298,12 +296,12 @@ func parsemsg(msg *irc_msg, foo bot) bool {
|
|||
if (c.groups != nil) {
|
||||
(*msg).retmsg = "Ignoring groups for the groups-adding. Well, what were you expecting...?"
|
||||
}
|
||||
addgroups(strings.Fields((&c).suffix), msg)
|
||||
addgroups(db, strings.Fields((&c).suffix), msg)
|
||||
return false
|
||||
}
|
||||
|
||||
// have a look at sorter table if command is valid
|
||||
if !checkSorter(msg, &c) {
|
||||
if !checkSorter(db, msg, &c) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -314,9 +312,9 @@ func parsemsg(msg *irc_msg, foo bot) bool {
|
|||
return false;
|
||||
}
|
||||
c.suffix = strings.Replace(c.suffix,"\"","'", -1)
|
||||
sendmsg(foo.conn, "horscchtey", addLine(msg, c.suffix, c.groups, c.cmd))
|
||||
sendmsg(conn, "horscchtey", addLine(db, msg, c.suffix, c.groups, c.cmd))
|
||||
} else {
|
||||
chooseEntry(msg, &c)
|
||||
chooseEntry(db, msg, &c)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue