Browse Source

Add game-specific modding info macro commands

master
NGnius (Graham) 3 years ago
parent
commit
71cd1ffbaf
5 changed files with 246 additions and 7 deletions
  1. +36
    -0
      src/command_definitions.rs
  2. +1
    -0
      src/discord.rs
  3. +10
    -5
      src/gitea_command.rs
  4. +188
    -0
      src/macros.rs
  5. +11
    -2
      src/main.rs

+ 36
- 0
src/command_definitions.rs View File

@@ -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<String>) {
}, Some("616329232389505055".to_string()))
}

// macros

// cardlife macro
pub fn def_cardlife() -> (discord::ApplicationCommand, Option<String>) {
(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<String>) {
(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<String>) {
(discord::ApplicationCommand {
id: None,
application_id: None,
name: "techblox".to_string(),
description: "Techblox mod information".to_string(),
options: None,
}, Some("616329232389505055".to_string()))
}


+ 1
- 0
src/discord.rs View File

@@ -203,6 +203,7 @@ pub struct InteractionApplicationCommandCallbackData {
pub content: String,
pub embeds: Option<Vec<Embed>>,
pub allowed_mentions: Option<String>,
pub flags: Option<usize>,
}

// embed and sub-objects


+ 10
- 5
src/gitea_command.rs View File

@@ -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,
})
}
}


+ 188
- 0
src/macros.rs View File

@@ -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<usize> {
if id == "106537989684887552" /* NGnius */ {
return None;
} else {
return Some(64);
}
}

+ 11
- 2
src/main.rs View File

@@ -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<InteractionResponseR
"hello-world" => 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();
}


Loading…
Cancel
Save