From 56c6d84813d1910da8980ac9e9f5311cd370734a Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 17 Jan 2016 12:20:16 -0500 Subject: [PATCH] Add TODO, small fix to factoid web interface --- TODO.md | 24 ++++++++++++++++++++++++ bot/bot.go | 3 +++ plugins/factoid.go | 7 ++++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..fe61e68 --- /dev/null +++ b/TODO.md @@ -0,0 +1,24 @@ +# TODO + +## Preface + +This bot was written a long time back in the spare time of a busy person. The code is often ugly and probably not idiomatic. Updating that to a modern testable codebase may be obnoxious, but every complete rewrite tends to end in stagnation, and this codebase does seem to work for the most part. You will not hurt the original author's feelings by fixing what's bad and refactoring what's good. + +## Never going to get done: + +* Migrate SQL to something that can marshal into structs + * https://github.com/jmoiron/sqlx +* Fix plugin structure to not have so many exported fields. None of them need to be exporting the bot reference, for example. +* Perhaps refactor a bit so stuff can be tested +* Fix names in factoid to actually match the bucket terminology. Some things are migrated, but not everything. There should be no instances of: + * Trigger + * Action + * FullText + * Operator +* Figure out something better for time? + * SQLite has a datetime, but the driver can't seem to handle null + * SQLite sometimes returns a different date string, which appers to be what the driver is trying to translate from/to +* Implement factoid aliasing +* Implement an object system for the give/take commands +* Create some kind of web reference page +* Enter all of this into GitHub tickets diff --git a/bot/bot.go b/bot/bot.go index a78fb9b..2da3966 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -38,6 +38,9 @@ type Bot struct { Config *config.Config // SQL DB + // TODO: I think it'd be nice to use https://github.com/jmoiron/sqlx so that + // the select/update/etc statements could be simplified with struct + // marshalling. DB *sql.DB DBVersion int64 diff --git a/plugins/factoid.go b/plugins/factoid.go index 17a1be8..877814b 100644 --- a/plugins/factoid.go +++ b/plugins/factoid.go @@ -654,9 +654,10 @@ func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) { "linkify": linkify, } if e := r.FormValue("entry"); e != "" { - var entries []factoid - // TODO: Fix the web interface with text search? - // p.Coll.Find(bson.M{"trigger": bson.M{"$regex": strings.ToLower(e)}}).All(&entries) + entries, err := getFacts(p.db, e) + if err != nil { + log.Println("Web error searching: ", err) + } context["Count"] = fmt.Sprintf("%d", len(entries)) context["Entries"] = entries context["Search"] = e