(
state: &Rc<RefCell<OpState>>,
rt_ctx: &RuntimeContext,
channel_id: Id<ChannelMarker>,
)
| 40 | } |
| 41 | |
| 42 | pub(crate) async fn get_guild_channel( |
| 43 | state: &Rc<RefCell<OpState>>, |
| 44 | rt_ctx: &RuntimeContext, |
| 45 | channel_id: Id<ChannelMarker>, |
| 46 | ) -> Result<Channel, AnyError> { |
| 47 | match rt_ctx |
| 48 | .bot_state |
| 49 | .get_channel(rt_ctx.guild_id, channel_id) |
| 50 | .await? |
| 51 | { |
| 52 | Some(c) => { |
| 53 | if !matches!(c.guild_id, Some(guild_id) if guild_id == rt_ctx.guild_id) { |
| 54 | Err(not_found_error(format!("channel `{channel_id} not found`"))) |
| 55 | } else { |
| 56 | Ok(c) |
| 57 | } |
| 58 | } |
| 59 | None => { |
| 60 | let cloned_discord = rt_ctx.discord_config.clone(); |
| 61 | |
| 62 | let channel = discord_request(state, async move { |
| 63 | cloned_discord.client.channel(channel_id).await |
| 64 | }) |
| 65 | .await? |
| 66 | .model() |
| 67 | .await?; |
| 68 | |
| 69 | if matches!(channel.guild_id, Some(guild_id) if guild_id == rt_ctx.guild_id) { |
| 70 | Ok(channel) |
| 71 | } else { |
| 72 | Err(not_found_error(format!("channel `{channel_id} not found`"))) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | pub(crate) fn parse_str_snowflake_id(id_str: &str) -> Result<Id<GenericMarker>, AnyError> { |
| 79 | if let Some(id) = Id::new_checked(id_str.parse()?) { |
no test coverage detected