bumped to rc.7. embed avatar inside executable. nudge now outputs the current nudge when ran with no arguments
This commit is contained in:
parent
50fb28d226
commit
8e567bf10b
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1165,7 +1165,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reminder_rs"
|
name = "reminder_rs"
|
||||||
version = "1.0.0-rc.6"
|
version = "1.0.0-rc.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"Inflector",
|
"Inflector",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "reminder_rs"
|
name = "reminder_rs"
|
||||||
version = "1.0.0-rc.6"
|
version = "1.0.0-rc.7"
|
||||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ Serenity and Rust are proving wonders for SoundFX. This is all in an effort to r
|
|||||||
You'll need rustc and cargo for compilation. To run, you'll need Python 3 still (due to no suitable replacement for dateparser in Rust)
|
You'll need rustc and cargo for compilation. To run, you'll need Python 3 still (due to no suitable replacement for dateparser in Rust)
|
||||||
|
|
||||||
### Compiling
|
### Compiling
|
||||||
Reminder Bot can be built by running `cargo build --release` in the top level directory.
|
Reminder Bot can be built by running `cargo build --release` in the top level directory. It is necessary to create a folder called 'assets' containing an image file with its name specified in the environment as `WEBHOOK_AVATAR`, of dimensions 128x128px to be used as the webhook avatar.
|
||||||
|
|
||||||
### Setting up Python
|
### Setting up Python
|
||||||
Reminder Bot by default looks for a venv within it's working directory to run Python out of. To set up a venv, install `python3-venv` and run `python3 -m venv venv`. Then, run `source venv/bin/activate` to activate the venv, and do `pip install dateparser` to install the required library
|
Reminder Bot by default looks for a venv within it's working directory to run Python out of. To set up a venv, install `python3-venv` and run `python3 -m venv venv`. Then, run `source venv/bin/activate` to activate the venv, and do `pip install dateparser` to install the required library
|
||||||
|
@ -6,7 +6,7 @@ use serenity::{
|
|||||||
cache::Cache,
|
cache::Cache,
|
||||||
client::Context,
|
client::Context,
|
||||||
framework::standard::CommandResult,
|
framework::standard::CommandResult,
|
||||||
http::{AttachmentType, CacheHttp},
|
http::CacheHttp,
|
||||||
model::{
|
model::{
|
||||||
channel::GuildChannel,
|
channel::GuildChannel,
|
||||||
channel::Message,
|
channel::Message,
|
||||||
@ -23,7 +23,7 @@ use crate::{
|
|||||||
check_subscription_on_message,
|
check_subscription_on_message,
|
||||||
consts::{
|
consts::{
|
||||||
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION,
|
CHARACTERS, DAY, HOUR, LOCAL_TIMEZONE, MAX_TIME, MINUTE, MIN_INTERVAL, PYTHON_LOCATION,
|
||||||
REGEX_CHANNEL, REGEX_CHANNEL_USER, WEBHOOK_AVATAR,
|
REGEX_CHANNEL, REGEX_CHANNEL_USER,
|
||||||
},
|
},
|
||||||
framework::SendIterator,
|
framework::SendIterator,
|
||||||
models::{ChannelData, GuildData, Timer, UserData},
|
models::{ChannelData, GuildData, Timer, UserData},
|
||||||
@ -47,7 +47,6 @@ use std::{
|
|||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
default::Default,
|
default::Default,
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
path::Path,
|
|
||||||
string::ToString,
|
string::ToString,
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
@ -55,10 +54,17 @@ use std::{
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
fn shorthand_displacement(seconds: u64) -> String {
|
fn shorthand_displacement(seconds: u64) -> String {
|
||||||
|
let (days, seconds) = seconds.div_rem(&DAY);
|
||||||
let (hours, seconds) = seconds.div_rem(&HOUR);
|
let (hours, seconds) = seconds.div_rem(&HOUR);
|
||||||
let (minutes, seconds) = seconds.div_rem(&MINUTE);
|
let (minutes, seconds) = seconds.div_rem(&MINUTE);
|
||||||
|
|
||||||
format!("{:02}:{:02}:{:02}", hours, minutes, seconds)
|
let time_repr = format!("{:02}:{:02}:{:02}", hours, minutes, seconds);
|
||||||
|
|
||||||
|
if days > 0 {
|
||||||
|
format!("{} days, {}", days, time_repr)
|
||||||
|
} else {
|
||||||
|
time_repr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn longhand_displacement(seconds: u64) -> String {
|
fn longhand_displacement(seconds: u64) -> String {
|
||||||
@ -84,15 +90,24 @@ async fn create_webhook(
|
|||||||
ctx: impl CacheHttp,
|
ctx: impl CacheHttp,
|
||||||
channel: GuildChannel,
|
channel: GuildChannel,
|
||||||
name: impl Display,
|
name: impl Display,
|
||||||
avatar: Option<String>,
|
|
||||||
) -> SerenityResult<Webhook> {
|
) -> SerenityResult<Webhook> {
|
||||||
if let Some(path) = avatar {
|
channel
|
||||||
channel
|
.create_webhook_with_avatar(
|
||||||
.create_webhook_with_avatar(ctx.http(), name, AttachmentType::from(Path::new(&path)))
|
ctx.http(),
|
||||||
.await
|
name,
|
||||||
} else {
|
(
|
||||||
channel.create_webhook(ctx.http(), name).await
|
include_bytes!(concat!(
|
||||||
}
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
"/assets/",
|
||||||
|
env!(
|
||||||
|
"WEBHOOK_AVATAR",
|
||||||
|
"WEBHOOK_AVATAR not provided for compilation"
|
||||||
|
)
|
||||||
|
)) as &[u8],
|
||||||
|
env!("WEBHOOK_AVATAR"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
@ -249,10 +264,12 @@ async fn nudge(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
let _ = msg
|
let content = user_data
|
||||||
.channel_id
|
.response(&pool, "nudge/no_argument")
|
||||||
.say(&ctx, user_data.response(&pool, "nudge/invalid_time").await)
|
.await
|
||||||
.await;
|
.replace("{nudge}", &format!("{}s", &channel.nudge.to_string()));
|
||||||
|
|
||||||
|
let _ = msg.channel_id.say(&ctx, content).await;
|
||||||
} else {
|
} else {
|
||||||
let parser = TimeParser::new(args, user_data.timezone.parse().unwrap());
|
let parser = TimeParser::new(args, user_data.timezone.parse().unwrap());
|
||||||
let nudge_time = parser.displacement();
|
let nudge_time = parser.displacement();
|
||||||
@ -1234,10 +1251,7 @@ async fn create_reminder<T: TryInto<i64>, S: ToString + Type<MySql> + Encode<MyS
|
|||||||
|
|
||||||
if let Some(guild_channel) = channel.guild() {
|
if let Some(guild_channel) = channel.guild() {
|
||||||
if channel_data.webhook_token.is_none() || channel_data.webhook_id.is_none() {
|
if channel_data.webhook_token.is_none() || channel_data.webhook_id.is_none() {
|
||||||
if let Ok(webhook) =
|
if let Ok(webhook) = create_webhook(&ctx, guild_channel, "Reminder").await {
|
||||||
create_webhook(&ctx, guild_channel, "Reminder", WEBHOOK_AVATAR.clone())
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
channel_data.webhook_id = Some(webhook.id.as_u64().to_owned());
|
channel_data.webhook_id = Some(webhook.id.as_u64().to_owned());
|
||||||
channel_data.webhook_token = Some(webhook.token);
|
channel_data.webhook_token = Some(webhook.token);
|
||||||
|
|
||||||
|
@ -6,12 +6,10 @@ pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX
|
|||||||
|
|
||||||
const THEME_COLOR_FALLBACK: u32 = 0x8fb677;
|
const THEME_COLOR_FALLBACK: u32 = 0x8fb677;
|
||||||
|
|
||||||
use std::{collections::HashSet, env, iter::FromIterator, path::Path};
|
use std::{collections::HashSet, env, iter::FromIterator};
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use log::warn;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref SUBSCRIPTION_ROLES: HashSet<u64> = HashSet::from_iter(
|
pub static ref SUBSCRIPTION_ROLES: HashSet<u64> = HashSet::from_iter(
|
||||||
env::var("SUBSCRIPTION_ROLES")
|
env::var("SUBSCRIPTION_ROLES")
|
||||||
@ -55,18 +53,4 @@ lazy_static! {
|
|||||||
THEME_COLOR_FALLBACK,
|
THEME_COLOR_FALLBACK,
|
||||||
|inner| u32::from_str_radix(&inner, 16).unwrap_or(THEME_COLOR_FALLBACK)
|
|inner| u32::from_str_radix(&inner, 16).unwrap_or(THEME_COLOR_FALLBACK)
|
||||||
);
|
);
|
||||||
pub static ref WEBHOOK_AVATAR: Option<String> = env::var("WEBHOOK_AVATAR")
|
|
||||||
.ok()
|
|
||||||
.map(|s| {
|
|
||||||
let p = Path::new(&s);
|
|
||||||
|
|
||||||
if !p.exists() {
|
|
||||||
warn!("WEBHOOK_AVATAR path doesn't exist. Falling back");
|
|
||||||
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(s)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.flatten();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user