From 71cd1ffbaffe4684e87681d1543ece4ec75b127a Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 16 May 2021 20:57:28 -0400 Subject: [PATCH] Add game-specific modding info macro commands --- src/command_definitions.rs | 36 +++++++ src/discord.rs | 1 + src/gitea_command.rs | 15 ++- src/macros.rs | 188 +++++++++++++++++++++++++++++++++++++ src/main.rs | 13 ++- 5 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 src/macros.rs diff --git a/src/command_definitions.rs b/src/command_definitions.rs index 967688e..b0d9537 100644 --- a/src/command_definitions.rs +++ b/src/command_definitions.rs @@ -23,6 +23,7 @@ pub fn hello_world(interaction: &Interaction) -> InteractionResponse { content: format!("Hello {}!", cmd.member.nick.unwrap_or(cmd.member.user.unwrap().username)), allowed_mentions: None, embeds: None, + flags: None, }), } } @@ -81,3 +82,38 @@ pub fn def_gitea_issue() -> (discord::ApplicationCommand, Option) { }, Some("616329232389505055".to_string())) } +// macros + +// cardlife macro +pub fn def_cardlife() -> (discord::ApplicationCommand, Option) { + (discord::ApplicationCommand { + id: None, + application_id: None, + name: "cardlife".to_string(), + description: "Cardlife mod information".to_string(), + options: None, + }, Some("616329232389505055".to_string())) +} + +// robocraft macro +pub fn def_robocraft() -> (discord::ApplicationCommand, Option) { + (discord::ApplicationCommand { + id: None, + application_id: None, + name: "robocraft".to_string(), + description: "Robocraft mod information".to_string(), + options: None, + }, Some("616329232389505055".to_string())) +} + +// techblox macro +pub fn def_techblox() -> (discord::ApplicationCommand, Option) { + (discord::ApplicationCommand { + id: None, + application_id: None, + name: "techblox".to_string(), + description: "Techblox mod information".to_string(), + options: None, + }, Some("616329232389505055".to_string())) +} + diff --git a/src/discord.rs b/src/discord.rs index e6b755c..78bddde 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -203,6 +203,7 @@ pub struct InteractionApplicationCommandCallbackData { pub content: String, pub embeds: Option>, pub allowed_mentions: Option, + pub flags: Option, } // embed and sub-objects diff --git a/src/gitea_command.rs b/src/gitea_command.rs index efd3c9f..bb181cf 100644 --- a/src/gitea_command.rs +++ b/src/gitea_command.rs @@ -21,7 +21,8 @@ pub fn gitea_release(interaction: &Interaction) -> InteractionResponse { tts: false, content: format!("No releases found for {}'s {} repository", &username, &repo_name), embeds: None, - allowed_mentions: None + allowed_mentions: None, + flags: None, }) } } @@ -75,7 +76,8 @@ pub fn gitea_release(interaction: &Interaction) -> InteractionResponse { tts: false, content: "".to_string(), embeds: Some(vec![embed]), - allowed_mentions: None + allowed_mentions: None, + flags: None, }) } } else { @@ -84,7 +86,8 @@ pub fn gitea_release(interaction: &Interaction) -> InteractionResponse { tts: false, content: format!("Gitea error: `{}`", res.err().unwrap()), embeds: None, - allowed_mentions: None + allowed_mentions: None, + flags: None, }) } } @@ -175,7 +178,8 @@ pub fn gitea_issue(interaction: &Interaction) -> InteractionResponse { tts: false, content: "".to_string(), embeds: Some(vec![embed]), - allowed_mentions: None + allowed_mentions: None, + flags: None, }) } } else { @@ -184,7 +188,8 @@ pub fn gitea_issue(interaction: &Interaction) -> InteractionResponse { tts: false, content: format!("Gitea error: `{}`", res.err().unwrap()), embeds: None, - allowed_mentions: None + allowed_mentions: None, + flags: None, }) } } diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..bf56247 --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,188 @@ +use crate::discord::{Interaction, InteractionResponse, InteractionApplicationCommandCallbackData, Embed, EmbedFooter, EmbedAuthor, EmbedField}; + +pub fn cardlife(interaction: &Interaction) -> InteractionResponse { + let cmd = interaction.cmd().unwrap(); + // build embed + let embed = Embed { + title: Some("CLre and CLIPA".to_string()), + type_: None, + description: Some( +"Cardlife is no longer received updates, not even bugfixes. \ +To fix that, NGnius started the CLre mod to apply bugfixes to Cardlife. \ +With help from Zhang and other community members, CLre now fixes most critical bugs. + +CLre is a code mod that requires CLIPA to work. \ +CLIPA patches Cardlife so that it will load CLre and other compatible mods. \ +To install CLIPA, download the [latest release](https://git.exmods.org/NGnius/CLIPA/releases), \ +then follow [steps 2 through 4](https://git.exmods.org/NGnius/CLIPA#user-content-how-to-install) \ +or join the official Cardlife server for more in-depth instructions. \ +Once CLIPA is installed, \ +download the latest version of [CLre](https://git.exmods.org/NGnius/CLre/releases) and place it in the Plugins folder in your Cardlife install folder." + .to_string()), + url: None, + timestamp: None, + color: Some(0x00C800), // Colour::from_rgb(0, 200, 0) + footer: Some(EmbedFooter { + text: "NGnius".to_string(), + icon_url: Some("https://git.exmods.org/user/avatar/NGnius/-1".to_string()), + proxy_icon_url: None, + }), + image: None, + thumbnail: None, + video: None, + provider: None, + author: Some(EmbedAuthor { + name: Some("Cardlife Modding Overview".to_string()), + url: Some("https://exmods.org/".to_string()), + icon_url: None, + proxy_icon_url: None + }), + fields: Some(vec![ + EmbedField { + name: "CLre".to_string(), + value: "[view releases](https://git.exmods.org/NGnius/CLre/releases)".to_string(), + inline: Some(true), + }, + EmbedField { + name: "CLIPA".to_string(), + value: "[view releases](https://git.exmods.org/NGnius/CLIPA/releases)".to_string(), + inline: Some(true), + } + ]) + }; + InteractionResponse::ChannelMessageWithSource { + data: Some(InteractionApplicationCommandCallbackData { + tts: false, + content: "".to_string(), + allowed_mentions: None, + embeds: Some(vec![embed]), + flags: flag_by_user(&cmd.member.user.unwrap().id), + }), + } +} + +pub fn robocraft(interaction: &Interaction) -> InteractionResponse { + let cmd = interaction.cmd().unwrap(); + // build embed + let embed = Embed { + title: Some("RC2 and RCIPA".to_string()), + type_: None, + description: Some( +"Robocraft modding work is still WIP, but the RC2 mod adds some much-requested features to RC. \ +You must install RCIPA first to load mods such as RC2, but it's definitely worth it! \ +RCIPA also uses some quantum computing to circumvent EAC since that prevents modifications to Robocraft. + +RC2 adds rotating platforms and crossplay with Robocraft Infinity (the Xbox version). \ +The 100 garage bay limit is also removed. \ +Think Procelio meets the RC15 project, but without the uncertainty, monetization, and (potential) legal problems." + .to_string()), + url: None, + timestamp: None, + color: Some(0x00C800), // Colour::from_rgb(0, 200, 0) + footer: Some(EmbedFooter { + text: cmd.member.nick.unwrap_or(cmd.member.user.unwrap().username), + icon_url: Some("https://git.exmods.org/img/favicon.png".to_string()), + proxy_icon_url: None, + }), + image: None, + thumbnail: None, + video: None, + provider: None, + author: Some(EmbedAuthor { + name: Some("Robocraft Modding Overview".to_string()), + url: Some("http://zettagram.com/".to_string()), + icon_url: None, + proxy_icon_url: None + }), + fields: Some(vec![ + EmbedField { + name: "libfj".to_string(), + value: "[more info](https://github.com/NGnius/libfj)".to_string(), + inline: Some(true), + } + ]) + }; + InteractionResponse::ChannelMessageWithSource { + data: Some(InteractionApplicationCommandCallbackData { + tts: false, + content: "".to_string(), + allowed_mentions: None, + embeds: Some(vec![embed]), + flags: Some(64), + }), + } +} + +pub fn techblox(interaction: &Interaction) -> InteractionResponse { + let cmd = interaction.cmd().unwrap(); + // build embed + let embed = Embed { + title: Some("TechbloxModdingAPI and GCIPA".to_string()), + type_: None, + description: Some( +"Techblox is the latest iteration of Freejam's new sandbox game. \ +This iterative approach allows us to reuse some mod tools from Gamecraft like GCIPA. \ +TechbloxModdingAPI is a standard API that most mods use to interface with Techblox, \ +which is also adapted from it's Gamecraft counterpart. + +GCIPA patches Techblox so that it will load compatible mods. \ +To install GCIPA, download the [latest release](https://git.exmods.org/modtainers/GCIPA/releases), \ +then follow [steps 2 through 4](https://git.exmods.org/modtainers/GCIPA/releases) \ +or ask for more in-depth instructions. \ +Once GCIPA is installed, \ +download the latest version of [TechbloxModdingAPI](https://git.exmods.org/modtainers/GamecraftModdingAPI/releases) and place it in the Plugins folder in your Techblox install folder." + .to_string()), + url: None, + timestamp: None, + color: Some(0x00C800), // Colour::from_rgb(0, 200, 0) + footer: Some(EmbedFooter { + text: "NGnius".to_string(), + icon_url: Some("https://git.exmods.org/user/avatar/NGnius/-1".to_string()), + proxy_icon_url: None, + }), + image: None, + thumbnail: None, + video: None, + provider: None, + author: Some(EmbedAuthor { + name: Some("Techblox Modding Overview".to_string()), + url: Some("https://exmods.org/".to_string()), + icon_url: None, + proxy_icon_url: None + }), + fields: Some(vec![ + EmbedField { + name: "GCIPA".to_string(), + value: "[view releases](https://git.exmods.org/modtainers/GCIPA/releases)".to_string(), + inline: Some(true), + }, + EmbedField { + name: "TechbloxModdingAPI".to_string(), + value: "[view release](https://git.exmods.org/modtainers/GamecraftModdingAPI/releases)".to_string(), + inline: Some(true), + }, + EmbedField { + name: "Mods".to_string(), + value: "[view list](https://exmods.org/mods/)".to_string(), + inline: Some(true), + }, + ]) + }; + InteractionResponse::ChannelMessageWithSource { + data: Some(InteractionApplicationCommandCallbackData { + tts: false, + content: "".to_string(), + allowed_mentions: None, + embeds: Some(vec![embed]), + flags: flag_by_user(&cmd.member.user.unwrap().id), + }), + } +} + +fn flag_by_user(id: &str) -> Option { + if id == "106537989684887552" /* NGnius */ { + return None; + } else { + return Some(64); + } +} diff --git a/src/main.rs b/src/main.rs index f18a42c..99aaa5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod discord; mod command_definitions; mod gitea; mod gitea_command; +mod macros; #[macro_use] extern crate rocket; use lazy_static::lazy_static; @@ -13,8 +14,9 @@ use rocket_contrib::json::Json; use std::sync::RwLock; use crate::auth_tools::{AuthenticatedInteraction}; use crate::discord::{Interaction, InteractionResponse, InteractionResponseRaw, InteractionApplicationCommandCallbackData}; -use crate::command_definitions::{hello_world, def_hello_world, def_gitea_release, def_gitea_issue}; +use crate::command_definitions::{hello_world, def_hello_world, def_gitea_release, def_gitea_issue, def_cardlife, def_robocraft, def_techblox}; use crate::gitea_command::{gitea_release, gitea_issue}; +use crate::macros::{cardlife, robocraft, techblox}; static GLOBAL_COMMAND_KEY: &str = "GLOBAL command KEY"; @@ -34,12 +36,16 @@ fn root_post(interaction: AuthenticatedInteraction) -> Json hello_world(&interaction.interaction), "gitea-release" => gitea_release(&interaction.interaction), "gitea-issue" => gitea_issue(&interaction.interaction), + "cardlife" => cardlife(&interaction.interaction), + "robocraft" => robocraft(&interaction.interaction), + "techblox" => techblox(&interaction.interaction), _ => InteractionResponse::ChannelMessageWithSource { data: Some(InteractionApplicationCommandCallbackData { tts: false, content: "Oops, that's not implemented yet!".to_string(), embeds: None, - allowed_mentions: None + allowed_mentions: None, + flags: Some(64), }) }, } @@ -79,6 +85,9 @@ fn main() { register_command(&def_hello_world, &req_client); register_command(&def_gitea_release, &req_client); register_command(&def_gitea_issue, &req_client); + register_command(&def_cardlife, &req_client); + register_command(&def_robocraft, &req_client); + register_command(&def_techblox, &req_client); // start web server rocket::ignite().mount("/", routes![root_post, hello_get]).launch(); }