From 9ed3a8b8751168e5f9d693ef0aecb876190f792c Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sat, 14 Jun 2025 14:34:51 -0400 Subject: [PATCH] Why clog the code with uhOh, it panics anyway --- telegram/handlers.go | 69 +++++++++----------------------------------- telegram/utils.go | 5 +--- 2 files changed, 14 insertions(+), 60 deletions(-) diff --git a/telegram/handlers.go b/telegram/handlers.go index 96b4dfe..8d63971 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -16,10 +16,6 @@ import ( "github.com/zelenin/go-tdlib/client" ) -func uhOh() { - log.Fatal("Update type mismatch") -} - func int64SliceToStringSlice(ints []int64) []string { strings := make([]string, len(ints)) wg := sync.WaitGroup{} @@ -89,89 +85,50 @@ func (c *Client) updateHandler() { if update.GetClass() == client.ClassUpdate { switch update.GetType() { case client.TypeUpdateUser: - typedUpdate, ok := update.(*client.UpdateUser) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateUser) c.updateUser(typedUpdate) log.Debugf("%#v", typedUpdate.User) case client.TypeUpdateUserStatus: - typedUpdate, ok := update.(*client.UpdateUserStatus) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateUserStatus) c.updateUserStatus(typedUpdate) log.Debugf("%#v", typedUpdate.Status) case client.TypeUpdateNewChat: - typedUpdate, ok := update.(*client.UpdateNewChat) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateNewChat) c.updateNewChat(typedUpdate) log.Debugf("%#v", typedUpdate.Chat) case client.TypeUpdateChatPosition: - typedUpdate, ok := update.(*client.UpdateChatPosition) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateChatPosition) c.updateChatPosition(typedUpdate) log.Debugf("%#v", typedUpdate) case client.TypeUpdateChatLastMessage: - typedUpdate, ok := update.(*client.UpdateChatLastMessage) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateChatLastMessage) c.updateChatLastMessage(typedUpdate) log.Debugf("%#v", typedUpdate) case client.TypeUpdateNewMessage: - typedUpdate, ok := update.(*client.UpdateNewMessage) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateNewMessage) c.updateNewMessage(typedUpdate) log.Debugf("%#v", typedUpdate.Message) case client.TypeUpdateMessageContent: - typedUpdate, ok := update.(*client.UpdateMessageContent) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateMessageContent) c.updateMessageContent(typedUpdate) log.Debugf("%#v", typedUpdate.NewContent) case client.TypeUpdateDeleteMessages: - typedUpdate, ok := update.(*client.UpdateDeleteMessages) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateDeleteMessages) c.updateDeleteMessages(typedUpdate) case client.TypeUpdateAuthorizationState: - typedUpdate, ok := update.(*client.UpdateAuthorizationState) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateAuthorizationState) c.updateAuthorizationState(typedUpdate) case client.TypeUpdateMessageSendSucceeded: - typedUpdate, ok := update.(*client.UpdateMessageSendSucceeded) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateMessageSendSucceeded) c.updateMessageSendSucceeded(typedUpdate) case client.TypeUpdateMessageSendFailed: - typedUpdate, ok := update.(*client.UpdateMessageSendFailed) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateMessageSendFailed) c.updateMessageSendFailed(typedUpdate) case client.TypeUpdateChatTitle: - typedUpdate, ok := update.(*client.UpdateChatTitle) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateChatTitle) c.updateChatTitle(typedUpdate) case client.TypeUpdateChatReadOutbox: - typedUpdate, ok := update.(*client.UpdateChatReadOutbox) - if !ok { - uhOh() - } + typedUpdate, _ := update.(*client.UpdateChatReadOutbox) c.updateChatReadOutbox(typedUpdate) default: // log only handled types diff --git a/telegram/utils.go b/telegram/utils.go index f437fc9..65ee9d5 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -2119,10 +2119,7 @@ func (c *Client) getNLastMessages(chatID int64, limit *MessageLimit) ([]*client. case MessageLimitChars: // rough but why care if message.Content != nil && message.Content.MessageContentType() == client.TypeMessageText { - textContent, ok := message.Content.(*client.MessageText) - if !ok { - uhOh() - } + textContent, _ := message.Content.(*client.MessageText) if textContent.Text != nil { charsCount += len(textContent.Text.Text)