moved message sending to their own functions
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
### High priority:
|
||||||
|
- [x] Embed creation tool
|
||||||
|
|
||||||
|
### Medium priority:
|
||||||
|
- [ ] JSON -> Rules list
|
||||||
|
- [ ] Postfix calculator
|
||||||
|
- [ ] Postfic generator
|
||||||
|
- [ ] JSON -> BPS class init
|
||||||
|
- [ ] BPS args -> JSON
|
||||||
|
- [ ] Random tip (from ByteDice.net/data/loadingScreenTips.json)
|
||||||
|
- [ ] A command that just sends my socials
|
||||||
|
- [ ] Magic 8 ball
|
||||||
|
|
||||||
|
### Low priority:
|
||||||
|
- [ ] Particle of the week
|
||||||
|
* Starts a 1 week contest where people make particles based on a theme using BDE_ParticleSys
|
||||||
|
- [ ] Weekly coding competition
|
||||||
|
* Same as particle of the week but with coding
|
||||||
|
- [ ] Content update sender
|
||||||
|
* Automatically sends sneek peeks (like commit history or manual) of projects when theyre updated
|
||||||
|
- [ ] Language TLDR command
|
||||||
|
* Shows a TLDR with pros/cons on a programming language
|
||||||
|
- [ ] PowerPlate info viewer
|
||||||
|
* Shows basic info on a PowerPlate
|
||||||
+17
-43
@@ -1,6 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{send_embed, send_msg, Context, EmbedOptions, Error};
|
||||||
|
|
||||||
use poise::{serenity_prelude::{Color, CreateEmbed, OnlineStatus, Timestamp}, CreateReply};
|
use poise::serenity_prelude::{OnlineStatus, Timestamp};
|
||||||
|
|
||||||
|
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
@@ -9,15 +9,7 @@ pub async fn ping(
|
|||||||
#[description = "The text to echo back"] text: Option<String>,
|
#[description = "The text to echo back"] text: Option<String>,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
{
|
{
|
||||||
let t = text.unwrap_or_else(|| "Pong".to_string());
|
send_msg(ctx, text.unwrap_or_else(|| "Pong".to_string()), true).await?;
|
||||||
|
|
||||||
let r = CreateReply {
|
|
||||||
content: Some(t),
|
|
||||||
ephemeral: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
ctx.send(r).await?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -33,36 +25,19 @@ pub async fn stop(
|
|||||||
let should_stop = dev_enabled
|
let should_stop = dev_enabled
|
||||||
|| confirmation.unwrap_or_else(|| "".to_string()).to_lowercase() == "i want to stop the bot now";
|
|| confirmation.unwrap_or_else(|| "".to_string()).to_lowercase() == "i want to stop the bot now";
|
||||||
|
|
||||||
let r_success = CreateReply {
|
|
||||||
content: Some("Shutting down...".to_string()),
|
|
||||||
ephemeral: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let r_fail = CreateReply {
|
|
||||||
content: Some("Failed to shut down.".to_string()),
|
|
||||||
ephemeral: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
if should_stop {
|
if should_stop {
|
||||||
ctx.send(r_success).await?;
|
send_msg(ctx, "Shutting down...".to_string(), true).await?;
|
||||||
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
||||||
ctx.framework().shard_manager.shutdown_all().await;
|
ctx.framework().shard_manager.shutdown_all().await;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctx.send(r_fail).await?;
|
send_msg(ctx, "Failed to shut down.".to_string(), true).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn none_to_empty(string: Option<String>) -> String {
|
|
||||||
return string.unwrap_or_else(|| "".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
slash_command,
|
slash_command,
|
||||||
prefix_command,
|
prefix_command,
|
||||||
@@ -75,21 +50,20 @@ pub async fn embed(
|
|||||||
#[description = "Color of side strip."] color: Option<u32>,
|
#[description = "Color of side strip."] color: Option<u32>,
|
||||||
#[description = "A URL the title is bound to."] url: Option<String>,
|
#[description = "A URL the title is bound to."] url: Option<String>,
|
||||||
#[description = "Timestamp at bottom (best to leave empty)."] timestamp: Option<Timestamp>,
|
#[description = "Timestamp at bottom (best to leave empty)."] timestamp: Option<Timestamp>,
|
||||||
|
#[description = "Empheral (only visible to you)"] empheral: Option<bool>
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
{
|
{
|
||||||
let embed = CreateEmbed::new()
|
send_embed(
|
||||||
.title (none_to_empty(title))
|
ctx,
|
||||||
.description(description)
|
EmbedOptions {
|
||||||
.colour (Color::new(color.unwrap_or_else(|| 5793266)))
|
desc: description,
|
||||||
.url (none_to_empty(url))
|
title,
|
||||||
.timestamp (timestamp.unwrap_or_else(|| Timestamp::now()));
|
col: color,
|
||||||
|
url,
|
||||||
let r = CreateReply {
|
ts: timestamp,
|
||||||
embeds: vec![embed],
|
empheral: empheral.unwrap_or_else(|| false)
|
||||||
..Default::default()
|
}
|
||||||
};
|
).await?;
|
||||||
|
|
||||||
ctx.send(r).await?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
+71
-1
@@ -1,9 +1,10 @@
|
|||||||
mod cmds;
|
mod cmds;
|
||||||
mod events;
|
mod events;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude::{self as serenity, Color, CreateEmbed, Timestamp};
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
dev: bool
|
dev: bool
|
||||||
@@ -12,6 +13,28 @@ type Error = Box<dyn std::error::Error + Send + Sync>;
|
|||||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||||
|
|
||||||
|
|
||||||
|
struct EmbedOptions {
|
||||||
|
desc: String,
|
||||||
|
title: Option<String>,
|
||||||
|
col: Option<u32>,
|
||||||
|
url: Option<String>,
|
||||||
|
ts: Option<Timestamp>,
|
||||||
|
empheral: bool
|
||||||
|
}
|
||||||
|
impl Default for EmbedOptions {
|
||||||
|
fn default() -> Self {
|
||||||
|
return EmbedOptions {
|
||||||
|
desc: "default description".to_string(),
|
||||||
|
title: None,
|
||||||
|
col: None,
|
||||||
|
url: None,
|
||||||
|
ts: None,
|
||||||
|
empheral: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
@@ -54,3 +77,50 @@ async fn main() {
|
|||||||
println!("Starting bot...");
|
println!("Starting bot...");
|
||||||
bot.start().await.unwrap();
|
bot.start().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn none_to_empty(string: Option<String>) -> String {
|
||||||
|
return string.unwrap_or_else(|| "".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn send_msg(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
t: String,
|
||||||
|
empheral: bool
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let r = CreateReply {
|
||||||
|
content: Some(t),
|
||||||
|
ephemeral: Some(empheral),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(r).await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn send_embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
options: EmbedOptions,
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let embed = CreateEmbed::new()
|
||||||
|
.title (none_to_empty(options.title))
|
||||||
|
.description(options.desc)
|
||||||
|
.colour (Color::new(options.col.unwrap_or_else(|| 5793266)))
|
||||||
|
.url (none_to_empty(options.url))
|
||||||
|
.timestamp (options.ts.unwrap_or_else(|| Timestamp::now()));
|
||||||
|
|
||||||
|
let r = CreateReply {
|
||||||
|
embeds: vec![embed],
|
||||||
|
ephemeral: Some(options.empheral),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(r).await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user