bevy_discord_presence/config.rs
1use bevy::prelude::Resource;
2
3/// Configuration for the RPC plugin
4#[derive(Debug, Resource, Copy, Clone)]
5pub struct RPCConfig {
6 /// The Discord application ID
7 pub app_id: u64,
8 /// Whether to show the current time in the activity
9 pub show_time: bool,
10}
11
12impl Default for RPCConfig {
13 fn default() -> Self {
14 Self {
15 app_id: 425407036495495169,
16 show_time: true,
17 }
18 }
19}
20
21// TODO: Add guide on how to get `app_id`
22
23/// The main RPC plugin
24///
25/// # Arguments
26///
27/// * `config` - The configuration for the plugin. Vital field is `app_id`, as the Discord interactions cannot work without it.
28pub struct RPCPlugin {
29 /// The Discord config used by the plugin
30 pub config: RPCConfig,
31}
32
33impl RPCPlugin {
34 /// Create a new plugin instance from config values
35 pub fn new(app_id: u64, show_time: bool) -> Self {
36 Self {
37 config: RPCConfig { app_id, show_time },
38 }
39 }
40
41 /// Create a new plugin instance from the given config
42 ///
43 /// Alias of [`RPCPlugin::from`]
44 pub fn from_config(config: RPCConfig) -> Self {
45 Self::from(config)
46 }
47}
48
49impl From<RPCConfig> for RPCPlugin {
50 fn from(config: RPCConfig) -> Self {
51 Self { config }
52 }
53}