Skip to content

Commit

Permalink
Allow missing finishReason and update TDLib (#21)
Browse files Browse the repository at this point in the history
* maybe fixed gemini

* updated tdlib & fixed gemini

* nitpicks

* update TDLib to 1.8.38

---------

Co-authored-by: jel <25802745+jelni@users.noreply.github.com>
  • Loading branch information
DuckyBlender and jelni authored Oct 22, 2024
1 parent 189b089 commit 3b89e1b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[env]
TDLIB_COMMIT_HASH = "cb164927417f22811c74cd8678ed4a5ab7cb80ba"
TDLIB_COMMIT_HASH = "d321984b75fccdb76239529e8aadcf7f80b0e35a"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
craiyon-bot:
build: .
environment:
TDLIB_COMMIT_HASH: cb164927417f22811c74cd8678ed4a5ab7cb80ba
TDLIB_COMMIT_HASH: d321984b75fccdb76239529e8aadcf7f80b0e35a
USER_AGENT:
TELEGRAM_TOKEN:
API_ID:
Expand Down
2 changes: 1 addition & 1 deletion src/apis/makersuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub struct GenerateContentResponse {
#[serde(rename_all = "camelCase")]
pub struct Candidate {
pub content: Option<ContentResponse>,
pub finish_reason: String,
pub finish_reason: Option<String>,
pub citation_metadata: Option<CitationMetadata>,
}

Expand Down
8 changes: 5 additions & 3 deletions src/commands/makersuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl CommandTrait for GooglePalm {

struct GenerationProgress {
parts: Vec<PartResponse>,
finish_reason: String,
finish_reason: Option<String>,
citation_sources: Vec<CitationSource>,
}

Expand Down Expand Up @@ -326,8 +326,10 @@ impl GenerationProgress {
text.push('…');
}

if self.finish_reason != "STOP" {
write!(text, " [{}]", self.finish_reason).unwrap();
if let Some(finish_reason) = self.finish_reason.as_ref() {
if finish_reason != "STOP" {
write!(text, " [finish reason: {finish_reason}]").unwrap();
}
}

if !self.citation_sources.is_empty() {
Expand Down
16 changes: 8 additions & 8 deletions src/utilities/telegram_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum MessageAttachment<'a> {
Video(Cow<'a, Video>),
VideoNote(Cow<'a, VideoNote>),
VoiceNote(Cow<'a, VoiceNote>),
Story(Cow<'a, StoryContent>),
Story(Box<Cow<'a, StoryContent>>),
ChatChangePhoto(Cow<'a, ChatPhoto>),
}

Expand All @@ -49,7 +49,7 @@ impl MessageAttachment<'_> {
Self::Video(video) => &video.video,
Self::VideoNote(video_note) => &video_note.video,
Self::VoiceNote(voice_note) => &voice_note.voice,
Self::Story(story) => match story.borrow() {
Self::Story(story) => match story.as_ref().borrow() {
enums::StoryContent::Photo(photo) => largest_photo(&photo.photo.sizes).unwrap(),
enums::StoryContent::Video(video) => &video.video.video,
enums::StoryContent::Unsupported => {
Expand Down Expand Up @@ -78,7 +78,7 @@ impl MessageAttachment<'_> {
Self::Video(video) => &video.mime_type,
Self::VideoNote(_) => "video/mp4",
Self::VoiceNote(voice_note) => &voice_note.mime_type,
Self::Story(story) => match story.borrow() {
Self::Story(story) => match story.as_ref().borrow() {
enums::StoryContent::Photo(_) => "image/jpeg",
enums::StoryContent::Video(_) => "video/mp4",
enums::StoryContent::Unsupported => {
Expand Down Expand Up @@ -154,10 +154,10 @@ pub async fn get_message_attachment(

match story.content {
enums::StoryContent::Photo(_) => {
MessageAttachment::Story(Cow::Owned(story.content))
MessageAttachment::Story(Box::new(Cow::Owned(story.content)))
}
enums::StoryContent::Video(_) if not_only_images => {
MessageAttachment::Story(Cow::Owned(story.content))
MessageAttachment::Story(Box::new(Cow::Owned(story.content)))
}
_ => return Ok(None),
}
Expand Down Expand Up @@ -207,10 +207,10 @@ pub async fn get_message_attachment(

match story.content {
enums::StoryContent::Photo(_) => {
MessageAttachment::Story(Cow::Owned(story.content))
MessageAttachment::Story(Box::new(Cow::Owned(story.content)))
}
enums::StoryContent::Video(_) if not_only_images => {
MessageAttachment::Story(Cow::Owned(story.content))
MessageAttachment::Story(Box::new(Cow::Owned(story.content)))
}
_ => return Ok(None),
}
Expand Down Expand Up @@ -281,7 +281,7 @@ pub fn log_status_update(update: &UpdateChatMember, chat: &CompactChat) {
}

let status = match update.new_chat_member.status {
ChatMemberStatus::Member => "joined",
ChatMemberStatus::Member(_) => "joined",
ChatMemberStatus::Left => "left",
_ => return,
};
Expand Down
13 changes: 1 addition & 12 deletions src/utilities/test_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ pub fn command_context() -> CommandContext {
is_outgoing: false,
is_pinned: false,
is_from_offline: false,
can_be_edited: false,
can_be_forwarded: false,
can_be_replied_in_another_chat: false,
can_be_saved: false,
can_be_deleted_only_for_self: false,
can_be_deleted_for_all_users: false,
can_get_added_reactions: false,
can_get_statistics: false,
can_get_message_thread: false,
can_get_read_date: false,
can_get_viewers: false,
can_get_media_timestamp_links: false,
can_report_reactions: false,
has_timestamped_media: false,
is_channel_post: false,
is_topic_message: false,
Expand All @@ -72,6 +60,7 @@ pub fn command_context() -> CommandContext {
author_signature: "message_author_signature".into(),
media_album_id: 0,
effect_id: 0,
has_sensitive_content: false,
restriction_reason: "message_restriction_reason".into(),
content: MessageContent::MessageText(MessageText {
text: FormattedText { text: "message_content_text".into(), ..Default::default() },
Expand Down

0 comments on commit 3b89e1b

Please sign in to comment.