mirror of https://github.com/velour/catbase.git
Enable web interface
This commit is contained in:
parent
de3aba210a
commit
9d9771c097
|
@ -319,6 +319,9 @@ func (p *BeersPlugin) pullUntappd() ([]checkin, error) {
|
||||||
url := baseUrl + access_token + "&limit=25"
|
url := baseUrl + access_token + "&limit=25"
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return []checkin{}, err
|
||||||
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -23,13 +23,13 @@ import (
|
||||||
// factoid stores info about our factoid for lookup and later interaction
|
// factoid stores info about our factoid for lookup and later interaction
|
||||||
type factoid struct {
|
type factoid struct {
|
||||||
id sql.NullInt64
|
id sql.NullInt64
|
||||||
fact string
|
Fact string
|
||||||
tidbit string
|
Tidbit string
|
||||||
verb string
|
Verb string
|
||||||
owner string
|
Owner string
|
||||||
created time.Time
|
created time.Time
|
||||||
accessed time.Time
|
accessed time.Time
|
||||||
count int
|
Count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *factoid) save(db *sqlx.DB) error {
|
func (f *factoid) save(db *sqlx.DB) error {
|
||||||
|
@ -44,12 +44,12 @@ func (f *factoid) save(db *sqlx.DB) error {
|
||||||
accessed=?,
|
accessed=?,
|
||||||
count=?
|
count=?
|
||||||
where id=?`,
|
where id=?`,
|
||||||
f.fact,
|
f.Fact,
|
||||||
f.tidbit,
|
f.Tidbit,
|
||||||
f.verb,
|
f.Verb,
|
||||||
f.owner,
|
f.Owner,
|
||||||
f.accessed.Unix(),
|
f.accessed.Unix(),
|
||||||
f.count,
|
f.Count,
|
||||||
f.id.Int64)
|
f.id.Int64)
|
||||||
} else {
|
} else {
|
||||||
f.created = time.Now()
|
f.created = time.Now()
|
||||||
|
@ -64,13 +64,13 @@ func (f *factoid) save(db *sqlx.DB) error {
|
||||||
accessed,
|
accessed,
|
||||||
count
|
count
|
||||||
) values (?, ?, ?, ?, ?, ?, ?);`,
|
) values (?, ?, ?, ?, ?, ?, ?);`,
|
||||||
f.fact,
|
f.Fact,
|
||||||
f.tidbit,
|
f.Tidbit,
|
||||||
f.verb,
|
f.Verb,
|
||||||
f.owner,
|
f.Owner,
|
||||||
f.created.Unix(),
|
f.created.Unix(),
|
||||||
f.accessed.Unix(),
|
f.accessed.Unix(),
|
||||||
f.count,
|
f.Count,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -105,20 +105,20 @@ func getFacts(db *sqlx.DB, fact string) ([]*factoid, error) {
|
||||||
count
|
count
|
||||||
from factoid
|
from factoid
|
||||||
where fact like ?;`,
|
where fact like ?;`,
|
||||||
fact)
|
fmt.Sprintf("%%%s%%", fact))
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var f factoid
|
var f factoid
|
||||||
var tmpCreated int64
|
var tmpCreated int64
|
||||||
var tmpAccessed int64
|
var tmpAccessed int64
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&f.id,
|
&f.id,
|
||||||
&f.fact,
|
&f.Fact,
|
||||||
&f.tidbit,
|
&f.Tidbit,
|
||||||
&f.verb,
|
&f.Verb,
|
||||||
&f.owner,
|
&f.Owner,
|
||||||
&tmpCreated,
|
&tmpCreated,
|
||||||
&tmpAccessed,
|
&tmpAccessed,
|
||||||
&f.count,
|
&f.Count,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -146,13 +146,13 @@ func getSingle(db *sqlx.DB) (*factoid, error) {
|
||||||
from factoid
|
from factoid
|
||||||
order by random() limit 1;`).Scan(
|
order by random() limit 1;`).Scan(
|
||||||
&f.id,
|
&f.id,
|
||||||
&f.fact,
|
&f.Fact,
|
||||||
&f.tidbit,
|
&f.Tidbit,
|
||||||
&f.verb,
|
&f.Verb,
|
||||||
&f.owner,
|
&f.Owner,
|
||||||
&tmpCreated,
|
&tmpCreated,
|
||||||
&tmpAccessed,
|
&tmpAccessed,
|
||||||
&f.count,
|
&f.Count,
|
||||||
)
|
)
|
||||||
f.created = time.Unix(tmpCreated, 0)
|
f.created = time.Unix(tmpCreated, 0)
|
||||||
f.accessed = time.Unix(tmpAccessed, 0)
|
f.accessed = time.Unix(tmpAccessed, 0)
|
||||||
|
@ -177,13 +177,13 @@ func getSingleFact(db *sqlx.DB, fact string) (*factoid, error) {
|
||||||
order by random() limit 1;`,
|
order by random() limit 1;`,
|
||||||
fact).Scan(
|
fact).Scan(
|
||||||
&f.id,
|
&f.id,
|
||||||
&f.fact,
|
&f.Fact,
|
||||||
&f.tidbit,
|
&f.Tidbit,
|
||||||
&f.verb,
|
&f.Verb,
|
||||||
&f.owner,
|
&f.Owner,
|
||||||
&tmpCreated,
|
&tmpCreated,
|
||||||
&tmpAccessed,
|
&tmpAccessed,
|
||||||
&f.count,
|
&f.Count,
|
||||||
)
|
)
|
||||||
f.created = time.Unix(tmpCreated, 0)
|
f.created = time.Unix(tmpCreated, 0)
|
||||||
f.accessed = time.Unix(tmpAccessed, 0)
|
f.accessed = time.Unix(tmpAccessed, 0)
|
||||||
|
@ -284,13 +284,13 @@ func (p *FactoidPlugin) learnFact(message bot.Message, fact, verb, tidbit string
|
||||||
}
|
}
|
||||||
|
|
||||||
n := factoid{
|
n := factoid{
|
||||||
fact: fact,
|
Fact: fact,
|
||||||
tidbit: tidbit,
|
Tidbit: tidbit,
|
||||||
verb: verb,
|
Verb: verb,
|
||||||
owner: message.User.Name,
|
Owner: message.User.Name,
|
||||||
created: time.Now(),
|
created: time.Now(),
|
||||||
accessed: time.Now(),
|
accessed: time.Now(),
|
||||||
count: 0,
|
Count: 0,
|
||||||
}
|
}
|
||||||
p.LastFact = &n
|
p.LastFact = &n
|
||||||
err = n.save(p.db)
|
err = n.save(p.db)
|
||||||
|
@ -316,9 +316,9 @@ func (p *FactoidPlugin) findTrigger(fact string) (bool, *factoid) {
|
||||||
// sayFact spits out a fact to the channel and updates the fact in the database
|
// sayFact spits out a fact to the channel and updates the fact in the database
|
||||||
// with new time and count information
|
// with new time and count information
|
||||||
func (p *FactoidPlugin) sayFact(message bot.Message, fact factoid) {
|
func (p *FactoidPlugin) sayFact(message bot.Message, fact factoid) {
|
||||||
msg := p.Bot.Filter(message, fact.tidbit)
|
msg := p.Bot.Filter(message, fact.Tidbit)
|
||||||
full := p.Bot.Filter(message, fmt.Sprintf("%s %s %s",
|
full := p.Bot.Filter(message, fmt.Sprintf("%s %s %s",
|
||||||
fact.fact, fact.verb, fact.tidbit,
|
fact.Fact, fact.Verb, fact.Tidbit,
|
||||||
))
|
))
|
||||||
for i, m := 0, strings.Split(msg, "$and"); i < len(m) && i < 4; i++ {
|
for i, m := 0, strings.Split(msg, "$and"); i < len(m) && i < 4; i++ {
|
||||||
msg := strings.TrimSpace(m[i])
|
msg := strings.TrimSpace(m[i])
|
||||||
|
@ -326,9 +326,9 @@ func (p *FactoidPlugin) sayFact(message bot.Message, fact factoid) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if fact.verb == "action" {
|
if fact.Verb == "action" {
|
||||||
p.Bot.SendAction(message.Channel, msg)
|
p.Bot.SendAction(message.Channel, msg)
|
||||||
} else if fact.verb == "reply" {
|
} else if fact.Verb == "reply" {
|
||||||
p.Bot.SendMessage(message.Channel, msg)
|
p.Bot.SendMessage(message.Channel, msg)
|
||||||
} else {
|
} else {
|
||||||
p.Bot.SendMessage(message.Channel, full)
|
p.Bot.SendMessage(message.Channel, full)
|
||||||
|
@ -337,7 +337,7 @@ func (p *FactoidPlugin) sayFact(message bot.Message, fact factoid) {
|
||||||
|
|
||||||
// update fact tracking
|
// update fact tracking
|
||||||
fact.accessed = time.Now()
|
fact.accessed = time.Now()
|
||||||
fact.count += 1
|
fact.Count += 1
|
||||||
err := fact.save(p.db)
|
err := fact.save(p.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Could not update fact.\n")
|
log.Printf("Could not update fact.\n")
|
||||||
|
@ -374,7 +374,7 @@ func (p *FactoidPlugin) tellThemWhatThatWas(message bot.Message) bool {
|
||||||
msg = "Nope."
|
msg = "Nope."
|
||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintf("That was (#%d) '%s <%s> %s'",
|
msg = fmt.Sprintf("That was (#%d) '%s <%s> %s'",
|
||||||
fact.id.Int64, fact.fact, fact.verb, fact.tidbit)
|
fact.id.Int64, fact.Fact, fact.Verb, fact.Tidbit)
|
||||||
}
|
}
|
||||||
p.Bot.SendMessage(message.Channel, msg)
|
p.Bot.SendMessage(message.Channel, msg)
|
||||||
return true
|
return true
|
||||||
|
@ -431,13 +431,13 @@ func (p *FactoidPlugin) forgetLastFact(message bot.Message) bool {
|
||||||
p.Bot.SendMessage(message.Channel, "I refuse.")
|
p.Bot.SendMessage(message.Channel, "I refuse.")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if message.User.Admin || message.User.Name == p.LastFact.owner {
|
if message.User.Admin || message.User.Name == p.LastFact.Owner {
|
||||||
err := p.LastFact.delete(p.db)
|
err := p.LastFact.delete(p.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error removing fact: ", p.LastFact, err)
|
log.Println("Error removing fact: ", p.LastFact, err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Forgot #%d: %s %s %s\n", p.LastFact.id.Int64, p.LastFact.fact,
|
fmt.Printf("Forgot #%d: %s %s %s\n", p.LastFact.id.Int64, p.LastFact.Fact,
|
||||||
p.LastFact.verb, p.LastFact.tidbit)
|
p.LastFact.Verb, p.LastFact.Tidbit)
|
||||||
p.Bot.SendAction(message.Channel, "hits himself over the head with a skillet")
|
p.Bot.SendAction(message.Channel, "hits himself over the head with a skillet")
|
||||||
p.LastFact = nil
|
p.LastFact = nil
|
||||||
} else {
|
} else {
|
||||||
|
@ -470,7 +470,7 @@ func (p *FactoidPlugin) changeFact(message bot.Message) bool {
|
||||||
}
|
}
|
||||||
if !(message.User.Admin && userexp[len(userexp)-1] == 'g') {
|
if !(message.User.Admin && userexp[len(userexp)-1] == 'g') {
|
||||||
result = result[:1]
|
result = result[:1]
|
||||||
if result[0].owner != message.User.Name && !message.User.Admin {
|
if result[0].Owner != message.User.Name && !message.User.Admin {
|
||||||
p.Bot.SendMessage(message.Channel, "That's not your fact to edit.")
|
p.Bot.SendMessage(message.Channel, "That's not your fact to edit.")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -484,11 +484,11 @@ func (p *FactoidPlugin) changeFact(message bot.Message) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, fact := range result {
|
for _, fact := range result {
|
||||||
fact.fact = reg.ReplaceAllString(fact.fact, replace)
|
fact.Fact = reg.ReplaceAllString(fact.Fact, replace)
|
||||||
fact.fact = strings.ToLower(fact.fact)
|
fact.Fact = strings.ToLower(fact.Fact)
|
||||||
fact.verb = reg.ReplaceAllString(fact.verb, replace)
|
fact.Verb = reg.ReplaceAllString(fact.Verb, replace)
|
||||||
fact.tidbit = reg.ReplaceAllString(fact.tidbit, replace)
|
fact.Tidbit = reg.ReplaceAllString(fact.Tidbit, replace)
|
||||||
fact.count += 1
|
fact.Count += 1
|
||||||
fact.accessed = time.Now()
|
fact.accessed = time.Now()
|
||||||
fact.save(p.db)
|
fact.save(p.db)
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ func (p *FactoidPlugin) changeFact(message bot.Message) bool {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
msg = fmt.Sprintf("%s |", msg)
|
msg = fmt.Sprintf("%s |", msg)
|
||||||
}
|
}
|
||||||
msg = fmt.Sprintf("%s <%s> %s", msg, fact.verb, fact.tidbit)
|
msg = fmt.Sprintf("%s <%s> %s", msg, fact.Verb, fact.Tidbit)
|
||||||
}
|
}
|
||||||
if count > 4 {
|
if count > 4 {
|
||||||
msg = fmt.Sprintf("%s | ...and %d others", msg, count)
|
msg = fmt.Sprintf("%s | ...and %d others", msg, count)
|
||||||
|
@ -666,5 +666,8 @@ func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
t.Execute(w, context)
|
err = t.Execute(w, context)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,13 +92,13 @@ func (p *RememberPlugin) Message(message bot.Message) bool {
|
||||||
msg := strings.Join(msgs, "$and")
|
msg := strings.Join(msgs, "$and")
|
||||||
|
|
||||||
fact := factoid{
|
fact := factoid{
|
||||||
fact: strings.ToLower(trigger),
|
Fact: strings.ToLower(trigger),
|
||||||
verb: "reply",
|
Verb: "reply",
|
||||||
tidbit: msg,
|
Tidbit: msg,
|
||||||
owner: user.Name,
|
Owner: user.Name,
|
||||||
created: time.Now(),
|
created: time.Now(),
|
||||||
accessed: time.Now(),
|
accessed: time.Now(),
|
||||||
count: 0,
|
Count: 0,
|
||||||
}
|
}
|
||||||
if err := fact.save(p.db); err != nil {
|
if err := fact.save(p.db); err != nil {
|
||||||
log.Println("ERROR!!!!:", err)
|
log.Println("ERROR!!!!:", err)
|
||||||
|
@ -145,13 +145,13 @@ func (p *RememberPlugin) randQuote() string {
|
||||||
err := p.db.QueryRow(`select * from factoid where fact like '%quotes'
|
err := p.db.QueryRow(`select * from factoid where fact like '%quotes'
|
||||||
order by random() limit 1;`).Scan(
|
order by random() limit 1;`).Scan(
|
||||||
&f.id,
|
&f.id,
|
||||||
&f.fact,
|
&f.Fact,
|
||||||
&f.tidbit,
|
&f.Tidbit,
|
||||||
&f.verb,
|
&f.Verb,
|
||||||
&f.owner,
|
&f.Owner,
|
||||||
&tmpCreated,
|
&tmpCreated,
|
||||||
&tmpAccessed,
|
&tmpAccessed,
|
||||||
&f.count,
|
&f.Count,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error getting quotes: ", err)
|
log.Println("Error getting quotes: ", err)
|
||||||
|
@ -160,7 +160,7 @@ func (p *RememberPlugin) randQuote() string {
|
||||||
f.created = time.Unix(tmpCreated, 0)
|
f.created = time.Unix(tmpCreated, 0)
|
||||||
f.accessed = time.Unix(tmpAccessed, 0)
|
f.accessed = time.Unix(tmpAccessed, 0)
|
||||||
|
|
||||||
return f.tidbit
|
return f.Tidbit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RememberPlugin) quoteTimer(channel string) {
|
func (p *RememberPlugin) quoteTimer(channel string) {
|
||||||
|
|
|
@ -89,10 +89,10 @@ var factoidIndex string = `
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range .Entries}}
|
{{range .Entries}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.Trigger}}</td>
|
<td>{{linkify .Fact}}</td>
|
||||||
<td>{{linkify .FullText}}</td>
|
<td>{{linkify .Tidbit}}</td>
|
||||||
<td>{{.CreatedBy}}</td>
|
<td>{{linkify .Owner}}</td>
|
||||||
<td>{{.AccessCount}}</td>
|
<td>{{.Count}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in New Issue