added help for natural command. added prefix_from_id for guilddata
This commit is contained in:
parent
8a0588b04e
commit
4f3789aeed
@ -53,7 +53,6 @@ use sqlx::{
|
|||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
|
|
||||||
use num_integer::Integer;
|
use num_integer::Integer;
|
||||||
use num_traits::cast::ToPrimitive;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
@ -744,15 +743,13 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
|||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Some(timestamp) = python_call.ok().map(|inner| {
|
if let Some(timestamp) = python_call.ok().map(|inner|
|
||||||
println!("{}", from_utf8(&*inner.stdout).unwrap());
|
|
||||||
|
|
||||||
if inner.status.success() {
|
if inner.status.success() {
|
||||||
Some(from_utf8(&*inner.stdout).unwrap().parse::<i64>().unwrap())
|
Some(from_utf8(&*inner.stdout).unwrap().parse::<i64>().unwrap())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
None
|
None
|
||||||
}}).flatten() {
|
}).flatten() {
|
||||||
|
|
||||||
let mut location_ids = vec![ReminderScope::Channel(msg.channel_id.as_u64().to_owned())];
|
let mut location_ids = vec![ReminderScope::Channel(msg.channel_id.as_u64().to_owned())];
|
||||||
let mut content = msg_crop;
|
let mut content = msg_crop;
|
||||||
@ -798,20 +795,24 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
|||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
issue_count += 1;
|
issue_count += 1;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
println!("{:?}", res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = msg.channel_id.say(&ctx, format!("successfully set {} reminders", issue_count)).await;
|
let _ = msg.channel_id.say(&ctx, format!("successfully set {} reminders", issue_count)).await;
|
||||||
}
|
}
|
||||||
// something not right with the time parse
|
// something not right with the time parse
|
||||||
else {
|
else {
|
||||||
println!("ewifjewiof");
|
let _ = msg.channel_id.say(&ctx, "DEV ERROR: Failed to invoke Python").await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println!("aaaaaaaaaaaaaaaaaaa");
|
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool).await;
|
||||||
|
|
||||||
|
let resp = user_data.response(&pool, "natural/no_argument").await.replace("{prefix}", &prefix);
|
||||||
|
|
||||||
|
let _ = msg.channel_id.send_message(&ctx, |m| m
|
||||||
|
.embed(|e| e
|
||||||
|
.description(resp)
|
||||||
|
)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use serenity::{
|
use serenity::{
|
||||||
http::CacheHttp,
|
http::CacheHttp,
|
||||||
model::{
|
model::{
|
||||||
|
id::GuildId,
|
||||||
guild::Guild,
|
guild::Guild,
|
||||||
channel::Channel,
|
channel::Channel,
|
||||||
user::User,
|
user::User,
|
||||||
@ -20,6 +21,25 @@ pub struct GuildData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GuildData {
|
impl GuildData {
|
||||||
|
pub async fn prefix_from_id<T: Into<GuildId>>(guild_id_opt: Option<T>, pool: &MySqlPool) -> String {
|
||||||
|
if let Some(guild_id) = guild_id_opt {
|
||||||
|
let guild_id = guild_id.into().as_u64().to_owned();
|
||||||
|
|
||||||
|
let row = sqlx::query!(
|
||||||
|
"
|
||||||
|
SELECT prefix FROM guilds WHERE guild = ?
|
||||||
|
", guild_id
|
||||||
|
)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
row.map_or("$".to_string(), |r| r.prefix)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
"$".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
||||||
let guild_id = guild.id.as_u64().to_owned();
|
let guild_id = guild.id.as_u64().to_owned();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user