mirror of https://github.com/velour/catbase.git
Undo a horrible git thing
This commit is contained in:
parent
5d6f41db3c
commit
01056f1956
|
@ -48,7 +48,8 @@ func (fe *FirstEntry) save(db *sqlx.DB) error {
|
||||||
|
|
||||||
// NewFirstPlugin creates a new FirstPlugin with the Plugin interface
|
// NewFirstPlugin creates a new FirstPlugin with the Plugin interface
|
||||||
func New(b bot.Bot) *FirstPlugin {
|
func New(b bot.Bot) *FirstPlugin {
|
||||||
_, err := b.DB().Exec(`create table if not exists last (
|
if b.DBVersion() == 1 {
|
||||||
|
_, err := b.DB().Exec(`create table if not exists first (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
day integer,
|
day integer,
|
||||||
time integer,
|
time integer,
|
||||||
|
@ -58,20 +59,11 @@ func New(b bot.Bot) *FirstPlugin {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Could not create first table: ", err)
|
log.Fatal("Could not create first table: ", err)
|
||||||
}
|
}
|
||||||
_, err = b.DB().Exec(`create table if not exists first (
|
|
||||||
id integer primary key,
|
|
||||||
day integer,
|
|
||||||
time integer,
|
|
||||||
body string,
|
|
||||||
nick string
|
|
||||||
);`)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Could not create first table: ", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("First plugin initialized with day:", midnight(time.Now()))
|
log.Println("First plugin initialized with day:", midnight(time.Now()))
|
||||||
|
|
||||||
first, _, err := getLastFirst(b.DB())
|
first, err := getLastFirst(b.DB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Could not initialize first plugin: ", err)
|
log.Fatal("Could not initialize first plugin: ", err)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +75,7 @@ func New(b bot.Bot) *FirstPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLastFirst(db *sqlx.DB) (*FirstEntry, *FirstEntry, error) {
|
func getLastFirst(db *sqlx.DB) (*FirstEntry, error) {
|
||||||
// Get last first entry
|
// Get last first entry
|
||||||
var id sql.NullInt64
|
var id sql.NullInt64
|
||||||
var day sql.NullInt64
|
var day sql.NullInt64
|
||||||
|
@ -104,50 +96,20 @@ func getLastFirst(db *sqlx.DB) (*FirstEntry, *FirstEntry, error) {
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows || !id.Valid:
|
case err == sql.ErrNoRows || !id.Valid:
|
||||||
log.Println("No previous first entries")
|
log.Println("No previous first entries")
|
||||||
return nil, nil, nil
|
return nil, nil
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Println("Error on first query row: ", err)
|
log.Println("Error on first query row: ", err)
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Println(id, day, timeEntered, body, nick)
|
log.Println(id, day, timeEntered, body, nick)
|
||||||
first := &FirstEntry{
|
return &FirstEntry{
|
||||||
id: id.Int64,
|
id: id.Int64,
|
||||||
day: time.Unix(day.Int64, 0),
|
day: time.Unix(day.Int64, 0),
|
||||||
time: time.Unix(timeEntered.Int64, 0),
|
time: time.Unix(timeEntered.Int64, 0),
|
||||||
body: body.String,
|
body: body.String,
|
||||||
nick: nick.String,
|
nick: nick.String,
|
||||||
saved: true,
|
saved: true,
|
||||||
}
|
}, nil
|
||||||
|
|
||||||
err = db.QueryRow(`select
|
|
||||||
id, max(day), time, body, nick from last
|
|
||||||
limit 1;
|
|
||||||
`).Scan(
|
|
||||||
&id,
|
|
||||||
&day,
|
|
||||||
&timeEntered,
|
|
||||||
&body,
|
|
||||||
&nick,
|
|
||||||
)
|
|
||||||
switch {
|
|
||||||
case err == sql.ErrNoRows || !id.Valid:
|
|
||||||
log.Println("No previous last entries")
|
|
||||||
return nil, nil, nil
|
|
||||||
case err != nil:
|
|
||||||
log.Println("Error on last query row: ", err)
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
log.Println(id, day, timeEntered, body, nick)
|
|
||||||
last := &FirstEntry{
|
|
||||||
id: id.Int64,
|
|
||||||
day: time.Unix(day.Int64, 0),
|
|
||||||
time: time.Unix(timeEntered.Int64, 0),
|
|
||||||
body: body.String,
|
|
||||||
nick: nick.String,
|
|
||||||
saved: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
return first, last, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func midnight(t time.Time) time.Time {
|
func midnight(t time.Time) time.Time {
|
||||||
|
|
Loading…
Reference in New Issue