Skip to content

Commit b1f8999

Browse files
committed
chore: update to latest grammers changes
1 parent 0af9276 commit b1f8999

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

lib/ferogram/src/context.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
//! Context module.
1010
11-
use std::{io, path::Path, pin::pin, sync::Arc, time::Duration};
11+
use std::{io, ops::Deref, path::Path, pin::pin, sync::Arc, time::Duration};
1212

1313
use futures_util::future::{Either, select};
1414
use grammers_client::{
1515
InvocationError, Update,
1616
types::{
17-
ActionSender, CallbackQuery, Chat, InlineQuery, InlineSend, InputMessage, Media, Message,
18-
PackedChat, Photo, User, media::Uploaded,
17+
self, ActionSender, Chat, InputMessage, Media, PackedChat, Photo, User,
18+
media::Uploaded,
19+
update::{CallbackQuery, InlineQuery, InlineSend, Message},
1920
},
2021
};
2122
use tokio::{
@@ -221,9 +222,11 @@ impl Context {
221222
/// let message = ctx.message().await;
222223
/// # }
223224
/// ```
224-
pub async fn message(&self) -> Option<Message> {
225+
pub async fn message(&self) -> Option<types::Message> {
225226
match self.update.as_ref().expect("No update") {
226-
Update::NewMessage(message) | Update::MessageEdited(message) => Some(message.clone()),
227+
Update::NewMessage(message) | Update::MessageEdited(message) => {
228+
Some(message.deref().clone())
229+
}
227230
Update::CallbackQuery(query) => {
228231
let message = query.load_message().await.expect("Failed to load message");
229232

@@ -339,7 +342,7 @@ impl Context {
339342
pub async fn send<M: Into<InputMessage>>(
340343
&self,
341344
message: M,
342-
) -> Result<Message, InvocationError> {
345+
) -> Result<types::Message, InvocationError> {
343346
if let Some(msg) = self.message().await {
344347
msg.respond(message).await
345348
} else {
@@ -375,7 +378,7 @@ impl Context {
375378
pub async fn reply<M: Into<InputMessage>>(
376379
&self,
377380
message: M,
378-
) -> Result<Message, InvocationError> {
381+
) -> Result<types::Message, InvocationError> {
379382
if let Some(msg) = self.message().await {
380383
msg.reply(message).await
381384
} else {
@@ -449,7 +452,7 @@ impl Context {
449452
/// # Errors
450453
///
451454
/// Returns an error if the reply message could not be retrieved.
452-
pub async fn get_reply(&self) -> Result<Option<Message>, InvocationError> {
455+
pub async fn get_reply(&self) -> Result<Option<types::Message>, InvocationError> {
453456
if let Some(msg) = self.message().await {
454457
msg.get_reply().await
455458
} else {
@@ -477,7 +480,7 @@ impl Context {
477480
pub async fn forward_to<C: Into<PackedChat>>(
478481
&self,
479482
chat: C,
480-
) -> Result<Message, InvocationError> {
483+
) -> Result<types::Message, InvocationError> {
481484
if let Some(msg) = self.message().await {
482485
msg.forward_to(chat).await
483486
} else {
@@ -547,7 +550,7 @@ impl Context {
547550
/// # Errors
548551
///
549552
/// Returns an error if the message could not be forwarded.
550-
pub async fn forward_to_self(&self) -> Result<Message, InvocationError> {
553+
pub async fn forward_to_self(&self) -> Result<types::Message, InvocationError> {
551554
if let Some(msg) = self.message().await {
552555
let chat = self.client().get_me().await?;
553556

@@ -578,7 +581,7 @@ impl Context {
578581
pub async fn edit_or_reply<M: Into<InputMessage>>(
579582
&self,
580583
message: M,
581-
) -> Result<Message, InvocationError> {
584+
) -> Result<types::Message, InvocationError> {
582585
if let Some(msg) = self.message().await {
583586
if let Some(query) = self.callback_query() {
584587
query.answer().edit(message).await?;
@@ -660,7 +663,10 @@ impl Context {
660663
/// # Errors
661664
///
662665
/// Returns an error if the message could not be retrieved.
663-
pub async fn get_message(&self, message_id: i32) -> Result<Option<Message>, InvocationError> {
666+
pub async fn get_message(
667+
&self,
668+
message_id: i32,
669+
) -> Result<Option<types::Message>, InvocationError> {
664670
self.get_messages(vec![message_id])
665671
.await
666672
.map(|mut v| v.pop().unwrap_or_default())
@@ -687,7 +693,7 @@ impl Context {
687693
pub async fn get_messages(
688694
&self,
689695
message_ids: Vec<i32>,
690-
) -> Result<Vec<Option<Message>>, InvocationError> {
696+
) -> Result<Vec<Option<types::Message>>, InvocationError> {
691697
self.client
692698
.get_messages_by_id(self.chat().expect("No chat"), &message_ids)
693699
.await
@@ -741,7 +747,7 @@ impl Context {
741747
&self,
742748
user: &User,
743749
limit: Option<usize>,
744-
) -> Result<Vec<Message>, InvocationError> {
750+
) -> Result<Vec<types::Message>, InvocationError> {
745751
let mut iter = self
746752
.client
747753
.iter_messages(self.chat().expect("No chat"))
@@ -780,7 +786,7 @@ impl Context {
780786
pub async fn get_messages_from_self(
781787
&self,
782788
limit: Option<usize>,
783-
) -> Result<Vec<Message>, InvocationError> {
789+
) -> Result<Vec<types::Message>, InvocationError> {
784790
let mut iter = self
785791
.client
786792
.iter_messages(self.chat().expect("No chat"))

lib/ferogram/src/filters/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub async fn has_animated_sticker(_: Client, update: Update) -> Flow {
388388
/// Pass if the update is a new chat member.
389389
pub async fn new_chat_member(_: Client, update: Update) -> bool {
390390
if let Update::Raw(raw_update) = update {
391-
return matches!(raw_update, tl::enums::Update::ChatParticipantAdd(_));
391+
return matches!(raw_update.raw, tl::enums::Update::ChatParticipantAdd(_));
392392
}
393393

394394
false
@@ -397,7 +397,7 @@ pub async fn new_chat_member(_: Client, update: Update) -> bool {
397397
/// Pass if the update is a left chat member.
398398
pub async fn left_chat_member(_: Client, update: Update) -> bool {
399399
if let Update::Raw(raw_update) = update {
400-
return matches!(raw_update, tl::enums::Update::ChatParticipantDelete(_));
400+
return matches!(raw_update.raw, tl::enums::Update::ChatParticipantDelete(_));
401401
}
402402

403403
false
@@ -407,7 +407,7 @@ pub async fn left_chat_member(_: Client, update: Update) -> bool {
407407
pub async fn typing(_: Client, update: Update) -> bool {
408408
if let Update::Raw(raw_update) = update {
409409
return matches!(
410-
raw_update,
410+
raw_update.raw,
411411
tl::enums::Update::UserTyping(_) | tl::enums::Update::ChatUserTyping(_)
412412
);
413413
}

0 commit comments

Comments
 (0)