浏览代码

Don't try to insert nothing into the database. Fixes #11

Tulir Asokan 3 年之前
父节点
当前提交
ac7be4bb4e
共有 2 个文件被更改,包括 8 次插入1 次删除
  1. 3 0
      database/message.go
  2. 5 1
      portal.go

+ 3 - 0
database/message.go

@@ -132,6 +132,9 @@ type MessagePart struct {
 }
 
 func (m *Message) MassInsert(msgs []MessagePart) {
+	if len(msgs) == 0 {
+		return
+	}
 	valueStringFormat := "($1, $%d, $2, $3, $4, $5, $6, $7, $%d)"
 	if m.db.Dialect == dbutil.SQLite {
 		valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")

+ 5 - 1
portal.go

@@ -645,7 +645,11 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
 			parts = append(parts, *part)
 		}
 	}
-	portal.markMessageHandled(msg.ID, 0, msg.Author.ID, ts, threadID, parts)
+	if len(parts) == 0 {
+		portal.log.Warnfln("Unhandled message %q", msg.ID)
+	} else {
+		portal.markMessageHandled(msg.ID, 0, msg.Author.ID, ts, threadID, parts)
+	}
 }
 
 func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Message) {