added way too many features for a single commit. Who cares though?
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
🎲 https://bytedice.net
|
||||||
+87
-3
@@ -1,11 +1,95 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
use poise::{serenity_prelude::{Color, CreateEmbed, OnlineStatus, Timestamp}, CreateReply};
|
||||||
|
|
||||||
|
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn ping(
|
pub async fn ping(
|
||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "The text to echo back"] text: String,
|
#[description = "The text to echo back"] text: Option<String>,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
{
|
{
|
||||||
ctx.reply(text).await?;
|
let t = text.unwrap_or_else(|| "Pong".to_string());
|
||||||
Ok(())
|
|
||||||
|
let r = CreateReply {
|
||||||
|
content: Some(t),
|
||||||
|
ephemeral: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(r).await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR")]
|
||||||
|
pub async fn stop(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Type \"i want to stop the bot now\" to confirm"] confirmation: Option<String>,
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let dev_enabled = ctx.data().dev;
|
||||||
|
let should_stop = dev_enabled
|
||||||
|
|| 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 {
|
||||||
|
ctx.send(r_success).await?;
|
||||||
|
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
||||||
|
ctx.framework().shard_manager.shutdown_all().await;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx.send(r_fail).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn none_to_empty(string: Option<String>) -> String {
|
||||||
|
return string.unwrap_or_else(|| "".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[poise::command(
|
||||||
|
slash_command,
|
||||||
|
prefix_command,
|
||||||
|
default_member_permissions = "ADMINISTRATOR"
|
||||||
|
)]
|
||||||
|
pub async fn embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Title of embed."] title: Option<String>,
|
||||||
|
#[description = "Body text of embed."] description: String,
|
||||||
|
#[description = "Color of side strip."] color: Option<u32>,
|
||||||
|
#[description = "A URL the title is bound to."] url: Option<String>,
|
||||||
|
#[description = "Timestamp at bottom (best to leave empty)."] timestamp: Option<Timestamp>,
|
||||||
|
) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let embed = CreateEmbed::new()
|
||||||
|
.title (none_to_empty(title))
|
||||||
|
.description(description)
|
||||||
|
.colour (Color::new(color.unwrap_or_else(|| 5793266)))
|
||||||
|
.url (none_to_empty(url))
|
||||||
|
.timestamp (timestamp.unwrap_or_else(|| Timestamp::now()));
|
||||||
|
|
||||||
|
let r = CreateReply {
|
||||||
|
embeds: vec![embed],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(r).await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
+11
-3
@@ -1,12 +1,12 @@
|
|||||||
use crate::{Data, Error};
|
use crate::{Data, Error};
|
||||||
|
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude::{self as serenity, ActivityData};
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
pub fn event_handler<'a>(
|
pub fn event_handler<'a>(
|
||||||
_ctx: &'a serenity::Context,
|
ctx: &'a serenity::Context,
|
||||||
event: &'a serenity::FullEvent,
|
event: &'a serenity::FullEvent,
|
||||||
_framework: poise::FrameworkContext<'a, Data, Error>,
|
_framework: poise::FrameworkContext<'a, Data, Error>,
|
||||||
_data: &'a Data,
|
_data: &'a Data,
|
||||||
@@ -18,7 +18,15 @@ pub fn event_handler<'a>(
|
|||||||
data_about_bot.user.name,
|
data_about_bot.user.name,
|
||||||
data_about_bot.user.id
|
data_about_bot.user.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let file_text = std::fs::read_to_string("./data/status.txt").unwrap();
|
||||||
|
let custom_activity = ActivityData::custom(file_text);
|
||||||
|
// TODO: make custom rich presence
|
||||||
|
//let playing_activity
|
||||||
|
|
||||||
|
ctx.online();
|
||||||
|
ctx.set_activity(Some(custom_activity));
|
||||||
}
|
}
|
||||||
Ok(())
|
return Ok(());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
+16
-3
@@ -1,15 +1,24 @@
|
|||||||
mod cmds;
|
mod cmds;
|
||||||
mod events;
|
mod events;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude as serenity;
|
||||||
|
|
||||||
struct Data {}
|
struct Data {
|
||||||
|
dev: bool
|
||||||
|
}
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
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>;
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let data = Data {
|
||||||
|
dev: args.contains(&"--dev".to_string())
|
||||||
|
};
|
||||||
|
|
||||||
let token = std::env::var("ASSISTANT_TOKEN").expect("missing ASSISTANT_TOKEN env var");
|
let token = std::env::var("ASSISTANT_TOKEN").expect("missing ASSISTANT_TOKEN env var");
|
||||||
let intents = serenity::GatewayIntents::all();
|
let intents = serenity::GatewayIntents::all();
|
||||||
|
|
||||||
@@ -21,14 +30,18 @@ async fn main() {
|
|||||||
|
|
||||||
let framework = poise::Framework::builder()
|
let framework = poise::Framework::builder()
|
||||||
.options(poise::FrameworkOptions {
|
.options(poise::FrameworkOptions {
|
||||||
commands: vec![cmds::ping()],
|
commands: vec![
|
||||||
|
cmds::ping(),
|
||||||
|
cmds::embed(),
|
||||||
|
cmds::stop()
|
||||||
|
],
|
||||||
event_handler: events::event_handler,
|
event_handler: events::event_handler,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.setup(|ctx, _ready, framework| {
|
.setup(|ctx, _ready, framework| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
Ok(Data {})
|
return Ok(data);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
Reference in New Issue
Block a user