]> git.t-ch.net - podium.git/commitdiff
inital commit
authorAlex Brow <tech@fission.t-ch.net>
Sun, 10 Sep 2023 22:48:31 +0000 (18:48 -0400)
committerAlex Brow <tech@fission.t-ch.net>
Sun, 10 Sep 2023 22:48:31 +0000 (18:48 -0400)
.idea/.gitignore [new file with mode: 0644]
.idea/inspectionProfiles/Project_Default.xml [new file with mode: 0644]
.idea/modules.xml [new file with mode: 0644]
.idea/podium.iml [new file with mode: 0644]
.idea/vcs.xml [new file with mode: 0644]
Cargo.lock [new file with mode: 0644]
main.scratch.rs [new file with mode: 0644]
src/utils.rs [new file with mode: 0644]

diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644 (file)
index 0000000..13566b8
--- /dev/null
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644 (file)
index 0000000..0aa8d95
--- /dev/null
@@ -0,0 +1,11 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
+      <Languages>
+        <language minSize="52" name="Rust" />
+      </Languages>
+    </inspection_tool>
+    <inspection_tool class="RsMainFunctionNotFound" enabled="false" level="ERROR" enabled_by_default="false" />
+  </profile>
+</component>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644 (file)
index 0000000..1d9c4ed
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/podium.iml" filepath="$PROJECT_DIR$/.idea/podium.iml" />
+    </modules>
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/podium.iml b/.idea/podium.iml
new file mode 100644 (file)
index 0000000..bc2cd87
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="CPP_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644 (file)
index 0000000..35eb1dd
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644 (file)
index 0000000..b25baaf
--- /dev/null
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "podium"
+version = "0.1.0"
diff --git a/main.scratch.rs b/main.scratch.rs
new file mode 100644 (file)
index 0000000..264e83b
--- /dev/null
@@ -0,0 +1,428 @@
+#![feature(prelude_import)]
+#[prelude_import]
+use std::prelude::rust_2021::*;
+#[macro_use]
+extern crate std;
+mod utils {
+
+    // let avatar = EmbedData::get_author_avatar_url(&ctx).await;
+
+    // match ctx.send(|f| f.embed(
+    //     |f| f.author(
+    //         |f| f.name(
+    //             format! {"{} | v{}",
+    //                      match &ctx.author().member {
+    //                          None => { &ctx.author().name }
+    //                          Some(m) => {
+    //                              match &m.nick {
+    //                                  None => { &ctx.author().name }
+    //                                  Some(n) => { &n }
+    //                              }
+    //                          }
+    //                      },
+    //                      &ctx.data().podman_version
+    //             }).icon_url(avatar)
+    //     ).title(
+    //         format!("Podman {}", match &v.version {
+    //             None => { "unknown" }
+    //             Some(v) => { v }
+    //         })
+    //     ).field(
+    //         "Podman Version",
+    //         format!("Podman v{}", match &v.version {
+    //             None => { "unknown" }
+    //             Some(v) => { v }
+    //         }),
+    //         true,
+    //     ).field(
+    //         "Api Version",
+    //         format!("API v{}", match &v.api_version {
+    //             None => { "unknown" }
+    //             Some(v) => { v }
+    //         }),
+    //         true,
+    //     )
+    // )).await {
+    //     Ok(_) => { Ok(()) }
+    //     Err(e) => { Err(Error::try_from(e).unwrap()) }
+    // }
+
+    use podman_api::Podman;
+    use poise::serenity_prelude as serenity;
+    pub(crate) struct EmbedData;
+    impl EmbedData {
+        pub(crate) async fn get_author_avatar_url(ctx: &Context<'_>) -> String {
+            match ctx.author_member().await {
+                None => {
+                    match "none" {
+                        tmp => {
+                            {
+                                ::std::io::_eprint(format_args!(
+                                    "[{0}:{1}] {2} = {3:#?}\n",
+                                    "src/utils.rs", 11u32, "\"none\"", &tmp
+                                ));
+                            };
+                            tmp
+                        }
+                    };
+                    match ctx.author().avatar_url() {
+                        None => {
+                            match "none" {
+                                tmp => {
+                                    {
+                                        ::std::io::_eprint(format_args!(
+                                            "[{0}:{1}] {2} = {3:#?}\n",
+                                            "src/utils.rs", 14u32, "\"none\"", &tmp
+                                        ));
+                                    };
+                                    tmp
+                                }
+                            };
+                            ctx.author().default_avatar_url()
+                        }
+                        Some(url) => {
+                            match "some" {
+                                tmp => {
+                                    {
+                                        ::std::io::_eprint(format_args!(
+                                            "[{0}:{1}] {2} = {3:#?}\n",
+                                            "src/utils.rs", 18u32, "\"some\"", &tmp
+                                        ));
+                                    };
+                                    tmp
+                                }
+                            };
+                            url
+                        }
+                    }
+                }
+                Some(member) => {
+                    match "some" {
+                        tmp => {
+                            {
+                                ::std::io::_eprint(format_args!(
+                                    "[{0}:{1}] {2} = {3:#?}\n",
+                                    "src/utils.rs", 24u32, "\"some\"", &tmp
+                                ));
+                            };
+                            tmp
+                        }
+                    };
+                    match member.avatar_url() {
+                        None => {
+                            match "none" {
+                                tmp => {
+                                    {
+                                        ::std::io::_eprint(format_args!(
+                                            "[{0}:{1}] {2} = {3:#?}\n",
+                                            "src/utils.rs", 27u32, "\"none\"", &tmp
+                                        ));
+                                    };
+                                    tmp
+                                }
+                            };
+                            match ctx.author().avatar_url() {
+                                None => {
+                                    match "none" {
+                                        tmp => {
+                                            {
+                                                ::std::io::_eprint(format_args!(
+                                                    "[{0}:{1}] {2} = {3:#?}\n",
+                                                    "src/utils.rs", 30u32, "\"none\"", &tmp
+                                                ));
+                                            };
+                                            tmp
+                                        }
+                                    };
+                                    ctx.author().default_avatar_url()
+                                }
+                                Some(url) => {
+                                    match "some" {
+                                        tmp => {
+                                            {
+                                                ::std::io::_eprint(format_args!(
+                                                    "[{0}:{1}] {2} = {3:#?}\n",
+                                                    "src/utils.rs", 34u32, "\"some\"", &tmp
+                                                ));
+                                            };
+                                            tmp
+                                        }
+                                    };
+                                    url
+                                }
+                            }
+                        }
+                        Some(url) => {
+                            match "some" {
+                                tmp => {
+                                    {
+                                        ::std::io::_eprint(format_args!(
+                                            "[{0}:{1}] {2} = {3:#?}\n",
+                                            "src/utils.rs", 40u32, "\"some\"", &tmp
+                                        ));
+                                    };
+                                    tmp
+                                }
+                            };
+                            url
+                        }
+                    }
+                }
+            }
+        }
+    }
+    pub(crate) struct Data {
+        pub(crate) podman: Podman,
+        pub(crate) podman_version: String,
+    }
+    pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;
+    pub(crate) type Context<'a> = poise::Context<'a, Data, Error>;
+    #[macro_export]
+    macro_rules! create_embed {
+        ($ctx : expr, $title : expr,
+        $($field_title : expr => $field_data : expr), *) =>
+        {
+            let avatar = EmbedData :: get_author_avatar_url($ctx).await ;
+            match
+            $ctx.send(| f |
+            f.embed(| f |
+            f.author(| f |
+            f.name(format!
+            ("{} | v{}", match $ctx.author().member
+            {
+                None => { $ctx.author().name } Some(m) =>
+                {
+                    match & m.nick
+                    { None => { $ctx.author().name } Some(n) => { & n } }
+                }
+            },
+            $ctx.data().podman_version)))).icon_url(avatar)).title($title).$(field($field_title,
+            $field_data, true)) *.await
+            {
+                Ok(_) => { Ok(()) } Err(e) =>
+                { Err(Error :: try_from(e).unwrap()) }
+            }
+        } ;
+    }
+}
+use std::process;
+use poise::serenity_prelude as serenity;
+use tokio;
+use podman_api::Podman;
+use poise::serenity_prelude::EntityType::Str;
+use crate::utils::*;
+#[allow(clippy::str_to_string)]
+fn version() -> ::poise::Command<
+    <Context<'static> as poise::_GetGenerics>::U,
+    <Context<'static> as poise::_GetGenerics>::E,
+> {
+    /// Display's the connected podman's version information
+    async fn inner(ctx: Context<'_>) -> Result<(), Error> {
+        match "Command status is being run" {
+            tmp => {
+                {
+                    ::std::io::_eprint(format_args!(
+                        "[{0}:{1}] {2} = {3:#?}\n",
+                        "src/main.rs", 16u32, "\"Command status is being run\"", &tmp
+                    ));
+                };
+                tmp
+            }
+        };
+        let v = match ctx.data().podman.version().await {
+            Ok(v) => v,
+            Err(e) => {
+                return match ctx
+                    .send(|f| {
+                        f.embed(|f| {
+                            f.author(|f| {
+                                f.name(match &ctx.author().member {
+                                    None => "unknown",
+                                    Some(m) => match &m.nick {
+                                        None => &ctx.author().name,
+                                        Some(n) => n,
+                                    },
+                                })
+                            })
+                            .description(format_args!("```{0}```", e))
+                            .title("An error has occurred")
+                        })
+                    })
+                    .await
+                {
+                    Ok(_) => Ok(()),
+                    Err(e) => Err(Error::try_from(e).unwrap()),
+                };
+            }
+        };
+        match &v {
+            tmp => {
+                {
+                    ::std::io::_eprint(format_args!(
+                        "[{0}:{1}] {2} = {3:#?}\n",
+                        "src/main.rs", 43u32, "&v", &tmp
+                    ));
+                };
+                tmp
+            }
+        };
+        (/*ERROR*/);
+        Ok(())
+    }
+    ::poise::Command {
+        prefix_action: Some(|ctx| {
+            Box::pin(async move {
+                let (..) = async {
+                    use ::poise::PopArgument as _;
+                    let ctx = ctx.serenity_context;
+                    let msg = ctx.msg;
+                    let args = ctx.args;
+                    let attachment_index = 0;
+                    let mut error: (Box<dyn std::error::Error + Send + Sync>, Option<String>) =
+                        (Box::new(::poise::TooManyArguments) as _, None);
+                    if args.is_empty() {
+                        return Ok(());
+                    };
+                    Err(error)
+                }
+                .await
+                .map_err(|(error, input)| {
+                    poise::FrameworkError::ArgumentParse {
+                        error,
+                        input,
+                        ctx: ctx.into(),
+                    }
+                })?;
+                if !ctx.framework.options.manual_cooldowns {
+                    ctx.command
+                        .cooldowns
+                        .lock()
+                        .unwrap()
+                        .start_cooldown(ctx.into());
+                }
+                inner(ctx.into())
+                    .await
+                    .map_err(|error| poise::FrameworkError::Command {
+                        error,
+                        ctx: ctx.into(),
+                    })
+            })
+        }),
+        slash_action: Some(|ctx| {
+            Box::pin(async move {
+                #[allow(clippy::needless_question_mark)]
+                let () = async {
+                    use ::poise::SlashArgumentHack;
+                    let (ctx, interaction, args) =
+                        (ctx.serenity_context, ctx.interaction, ctx.args);
+                    Ok::<_, ::poise::SlashArgError>(())
+                }
+                .await
+                .map_err(|error| match error {
+                    poise::SlashArgError::CommandStructureMismatch(description) => {
+                        poise::FrameworkError::CommandStructureMismatch { ctx, description }
+                    }
+                    poise::SlashArgError::Parse { error, input } => {
+                        poise::FrameworkError::ArgumentParse {
+                            ctx: ctx.into(),
+                            error,
+                            input: Some(input),
+                        }
+                    }
+                })?;
+                if !ctx.framework.options.manual_cooldowns {
+                    ctx.command
+                        .cooldowns
+                        .lock()
+                        .unwrap()
+                        .start_cooldown(ctx.into());
+                }
+                inner(ctx.into())
+                    .await
+                    .map_err(|error| poise::FrameworkError::Command {
+                        error,
+                        ctx: ctx.into(),
+                    })
+            })
+        }),
+        context_menu_action: None,
+        subcommands: ::alloc::vec::Vec::new(),
+        name: "version".to_string(),
+        name_localizations: std::collections::HashMap::from([]),
+        qualified_name: String::from("version"),
+        identifying_name: String::from("version"),
+        category: None,
+        description: Some("Display's the connected podman's version information".to_string()),
+        description_localizations: std::collections::HashMap::from([]),
+        help_text: None,
+        hide_in_help: false,
+        cooldowns: std::sync::Mutex::new(::poise::Cooldowns::new(::poise::CooldownConfig {
+            global: None.map(std::time::Duration::from_secs),
+            user: None.map(std::time::Duration::from_secs),
+            guild: None.map(std::time::Duration::from_secs),
+            channel: None.map(std::time::Duration::from_secs),
+            member: None.map(std::time::Duration::from_secs),
+        })),
+        reuse_response: false,
+        default_member_permissions: poise::serenity_prelude::Permissions::empty(),
+        required_permissions: poise::serenity_prelude::Permissions::empty(),
+        required_bot_permissions: poise::serenity_prelude::Permissions::empty(),
+        owners_only: false,
+        guild_only: false,
+        dm_only: false,
+        nsfw_only: false,
+        checks: ::alloc::vec::Vec::new(),
+        on_error: None,
+        parameters: ::alloc::vec::Vec::new(),
+        custom_data: Box::new(()),
+        aliases: &[],
+        invoke_on_edit: false,
+        track_deletion: false,
+        broadcast_typing: false,
+        context_menu_name: None,
+        ephemeral: false,
+        __non_exhaustive: (),
+    }
+}
+async fn main() -> Result<(), Err()> {
+    let podman = match Podman::new("unix:///run/podman/podman.sock") {
+        Ok(a) => a,
+        Err(e) => {
+            {
+                ::std::io::_eprint(format_args!("An error has occurred: {0}\n", e));
+            };
+            process::exit(32);
+        }
+    };
+    let framework = poise::Framework::builder()
+        .options(poise::FrameworkOptions {
+            commands: <[_]>::into_vec(
+                #[rustc_box]
+                ::alloc::boxed::Box::new([version()]),
+            ),
+            ..Default::default()
+        })
+        .token(std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"))
+        .intents(serenity::GatewayIntents::non_privileged())
+        .setup(|ctx, _ready, framework| {
+            Box::pin(async move {
+                poise::builtins::register_globally(ctx, &framework.options().commands).await?;
+                Ok(Data {
+                    podman,
+                    podman_version: match podman.version().await {
+                        Ok(v) => match v.version {
+                            None => String::from("Unknown"),
+                            Some(v) => v,
+                        },
+                        Err(e) => {
+                            {
+                                ::std::io::_eprint(format_args!("An error has occurred: {0}\n", e));
+                            };
+                            process::exit(31);
+                        }
+                    },
+                })
+            })
+        });
+    framework.run().await.unwrap();
+}
diff --git a/src/utils.rs b/src/utils.rs
new file mode 100644 (file)
index 0000000..c85c139
--- /dev/null
@@ -0,0 +1,56 @@
+use std::borrow::Cow;
+use podman_api::Podman;
+
+
+pub(crate) struct EmbedData;
+
+impl EmbedData {
+    pub(crate) async fn get_author_avatar_url(ctx: &Context<'_>) -> String {
+        match ctx.author_member().await {
+            None => {
+                dbg!("none");
+                match ctx.author().avatar_url() {
+                    None => {
+                        dbg!("none");
+                        ctx.author().default_avatar_url()
+                    }
+                    Some(url) => {
+                        dbg!("some");
+                        url
+                    }
+                }
+            }
+            Some(member) => {
+                dbg!("some");
+                match member.avatar_url() {
+                    None => {
+                        dbg!("none");
+                        match ctx.author().avatar_url() {
+                            None => {
+                                dbg!("none");
+                                ctx.author().default_avatar_url()
+                            }
+                            Some(url) => {
+                                dbg!("some");
+                                url
+                            }
+                        }
+                    }
+                    Some(url) => {
+                        dbg!("some");
+                        url
+                    }
+                }
+            }
+        }
+    }
+}
+
+pub(crate) struct Data {
+    pub(crate) podman: Podman,
+}
+
+// User data, which is stored and accessible in all command invocations
+pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;
+pub(crate) type Context<'a> = poise::Context<'a, Data, Error>;
+