mirror of
https://github.com/idanoo/gomatrixbot
synced 2025-07-01 08:02:21 +00:00
wtf
This commit is contained in:
parent
ff0ad306e7
commit
112abcdf36
2 changed files with 24 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
|||
package database
|
||||
|
||||
// GetLastUsedPic
|
||||
func (db *Database) GetLastUsedPic() (int64, string, error) {
|
||||
func (db *Database) GetLastUsedPic(increment bool) (int64, string, error) {
|
||||
min := db.getPicMinViewCount()
|
||||
var id int64
|
||||
var fileName string
|
||||
|
@ -15,7 +15,10 @@ func (db *Database) GetLastUsedPic() (int64, string, error) {
|
|||
row.Scan(&id, &fileName)
|
||||
}
|
||||
|
||||
db.incrementPicViewCount(id)
|
||||
if increment {
|
||||
// Increment the view count
|
||||
db.incrementPicViewCount(id)
|
||||
}
|
||||
|
||||
return id, fileName, nil
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ const fontSize = 42
|
|||
const BIRB_PATH = "/root/data/reaction_pics"
|
||||
|
||||
func (mtrx *MtrxClient) postBirb(ctx context.Context, evt *event.Event) {
|
||||
idd, birb, err := mtrx.db.GetLastUsedPic()
|
||||
idd, birb, err := mtrx.db.GetLastUsedPic(true)
|
||||
if err != nil {
|
||||
mtrx.c.Log.Err(err).Msg("Failed to get birb")
|
||||
return
|
||||
|
@ -59,39 +59,31 @@ func (mtrx *MtrxClient) postBirb(ctx context.Context, evt *event.Event) {
|
|||
}
|
||||
|
||||
func (mtrx *MtrxClient) postBirbWithText(ctx context.Context, evt *event.Event, text string, filename string) {
|
||||
var reader *os.File
|
||||
var err error
|
||||
increment := true
|
||||
if filename != "" {
|
||||
increment = false
|
||||
}
|
||||
|
||||
if filename == "" {
|
||||
// Do a lookup
|
||||
dbId, birb, err := mtrx.db.GetLastUsedPic()
|
||||
if err != nil {
|
||||
mtrx.sendMessage(ctx, evt.RoomID, "Failed to get an image "+err.Error()+". "+birb)
|
||||
return
|
||||
}
|
||||
reader, err = os.Open(BIRB_PATH + "/" + birb)
|
||||
if err != nil {
|
||||
mtrx.sendMessage(ctx, evt.RoomID, "Failed to load image "+err.Error()+". "+birb)
|
||||
mtrx.db.DeletePic(dbId)
|
||||
delete(mtrx.pics, dbId)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
birb := filename
|
||||
reader, err = os.Open(BIRB_PATH + "/" + birb)
|
||||
if err != nil {
|
||||
mtrx.sendMessage(ctx, evt.RoomID, "Failed to load image "+err.Error()+". "+birb)
|
||||
var id int64
|
||||
// Do a lookup
|
||||
dbId, birb, err := mtrx.db.GetLastUsedPic(increment)
|
||||
if err != nil {
|
||||
mtrx.sendMessage(ctx, evt.RoomID, "Failed to get an image "+err.Error()+". "+birb)
|
||||
return
|
||||
}
|
||||
reader, err := os.Open(BIRB_PATH + "/" + birb)
|
||||
if err != nil {
|
||||
mtrx.sendMessage(ctx, evt.RoomID, "Failed to load image "+err.Error()+". "+birb)
|
||||
if filename != "" {
|
||||
for k, v := range mtrx.pics {
|
||||
if v == birb {
|
||||
id = k
|
||||
dbId = k
|
||||
break
|
||||
}
|
||||
}
|
||||
mtrx.db.DeletePic(id)
|
||||
delete(mtrx.pics, id)
|
||||
return
|
||||
}
|
||||
mtrx.db.DeletePic(dbId)
|
||||
delete(mtrx.pics, dbId)
|
||||
return
|
||||
}
|
||||
|
||||
// do the swaps
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue