MCPcopy Create free account
hub / github.com/Botloader/botloader / get_guild_channel

Function get_guild_channel

components/runtime/src/extensions/mod.rs:42–76  ·  view source on GitHub ↗
(
    state: &Rc<RefCell<OpState>>,
    rt_ctx: &RuntimeContext,
    channel_id: Id<ChannelMarker>,
)

Source from the content-addressed store, hash-verified

40}
41
42pub(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
78pub(crate) fn parse_str_snowflake_id(id_str: &str) -> Result<Id<GenericMarker>, AnyError> {
79 if let Some(id) = Id::new_checked(id_str.parse()?) {

Calls 3

not_found_errorFunction · 0.85
discord_requestFunction · 0.85
get_channelMethod · 0.80

Tested by

no test coverage detected