this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add feature crash_on_unimplemented

This adds the feature crash_on_unimplemented.
Before it would crash on debug builds, but this locks it behind a
feature flag for better ease of use and less confusion.

Additionally fixes a readme example.

MrSnowy 34b0d14b c13eff4e

+19 -12
+5
Cargo.toml
··· 11 11 [workspace] 12 12 members = ["examples/examplebot", "macros"] 13 13 14 + 15 + [features] 16 + # This feature causes the bot to crash once it recieves an unimplemented dispatch event, useful for development. 17 + crash_on_unimplemented = [] 18 + 14 19 [dependencies] 15 20 anyhow = "1.0.102" 16 21 async-trait = "0.1.89"
+5 -3
README.md
··· 64 64 #[command(PingCommand)] 65 65 async fn execute(api: &FluxerApiHandler, feedback: &CommandFeedback) { 66 66 let data = feedback.data; 67 + let channel = Channel::new(&data.channel_id, api); 68 + let message = channel.message(&data.id); 69 + message.reply("pong").await?; 67 70 68 - send_reply(api, &data.channel_id, &data.id, "pong").await?; 69 71 Ok(()) 70 72 } 71 73 ``` ··· 78 80 # Dispatch events 79 81 Not all op codes are implemented currently, and not all dispatch events have been registered yet. The reason for the latter is that i choose for the most part to implement data structure myself instead of generating it from a spec. So whenever an unknown dispatch event hits it would print the json that was attempted to be sent, then i implement the structure from it. Which leads to the next paragraph. 80 82 81 - When developing a bot in debug mode, be wary as there is a certain panic that will occur when an unimplemented dispatch event occurs. It's there by design for my own ease of use ( So i have no choice but to implement the event if i don't want constant crashing ;3). While it's not optimal i do advise to use release mode for now while still a bunch of dispatch events are missing as it will only send an error log in the terminal for said dispatch event. 83 + If you want to help implement dispatch events, it would be good to enable the feature flag "crash_on_unimplemented", this will throw a panic the moment an unimplemented dispatch event occurs. It's there for my own ease of use ( So i have no choice but to implement the event if i don't want constant crashing ;3). Without this flag it will only send an error log in the terminal for said dispatch event. 82 84 83 85 # API 84 86 As far as API calls go there are very few implemented at the moment but are quite useful ones like: ··· 176 178 177 179 Ok(result) 178 180 } 179 - ``` 181 + ```
+9 -9
macros/src/dispatch.rs
··· 184 184 pub fn dispatch_deserialize(value: &serde_json::value::Value) -> Result<DispatchEvent, serde_json::Error>{ 185 185 Ok( 186 186 match value["t"].as_str().ok_or_else(||de::Error::custom("Failed to find field t"))? { 187 - #(#deserialize_elems)* 187 + #(#deserialize_elems)* 188 188 189 - #[cfg(not(debug_assertions))] 190 - _ => { 191 - error!("Unimplemented dispatch event with data: {}", value); 192 - DispatchEvent::None 193 - } 189 + #[cfg(not(feature = "crash_on_unimplemented"))] 190 + _ => { 191 + error!("Unimplemented dispatch event with data: {}", value); 192 + DispatchEvent::None 193 + } 194 194 195 - #[cfg(debug_assertions)] 196 - _ => panic!("Unimplemented dispatch event with data: {}", value), 197 - } 195 + #[cfg(feature = "crash_on_unimplemented")] 196 + _ => panic!("Unimplemented dispatch event with data: {}", value), 197 + } 198 198 ) 199 199 } 200 200 };