bumped sqlx -> 0.4, bumped reminder_rs -> 1.2.3, added a more descriptive message for not enough permissions. removed STRINGS_TABLE environment variable
This commit is contained in:
parent
19754d3bcc
commit
1927d381ab
899
Cargo.lock
generated
899
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reminder_rs"
|
||||
version = "1.2.2"
|
||||
version = "1.2.3"
|
||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||
edition = "2018"
|
||||
|
||||
@ -8,7 +8,7 @@ edition = "2018"
|
||||
dotenv = "0.15"
|
||||
tokio = { version = "0.2", features = ["process"] }
|
||||
reqwest = { version = "0.10", features = ["rustls-tls"] }
|
||||
sqlx = { version = "0.3", default-features = false, features = ["runtime-tokio", "macros", "mysql", "bigdecimal", "chrono"] }
|
||||
sqlx = { version = "0.4", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"] }
|
||||
regex = "1.3"
|
||||
async-trait = "0.1"
|
||||
log = "0.4"
|
||||
|
@ -492,7 +492,7 @@ LIMIT
|
||||
.await
|
||||
}
|
||||
} else {
|
||||
sqlx::query_as!(
|
||||
sqlx::query_as_unchecked!(
|
||||
LookReminder,
|
||||
"
|
||||
SELECT
|
||||
@ -584,7 +584,7 @@ async fn delete(ctx: &Context, msg: &Message, _args: String) {
|
||||
.await;
|
||||
|
||||
let reminders = if let Some(guild_id) = msg.guild_id.map(|f| f.as_u64().to_owned()) {
|
||||
sqlx::query_as!(
|
||||
sqlx::query_as_unchecked!(
|
||||
LookReminder,
|
||||
"
|
||||
SELECT
|
||||
@ -1303,7 +1303,7 @@ async fn natural(ctx: &Context, msg: &Message, args: String) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_reminder<T: TryInto<i64>, S: ToString + Type<MySql> + Encode<MySql>>(
|
||||
async fn create_reminder<'a, T: TryInto<i64>, S: ToString + Type<MySql> + Encode<'a, MySql>>(
|
||||
ctx: impl CacheHttp,
|
||||
pool: &MySqlPool,
|
||||
user_id: u64,
|
||||
|
@ -46,8 +46,6 @@ lazy_static! {
|
||||
env::var("LOCAL_LANGUAGE").unwrap_or_else(|_| "EN".to_string());
|
||||
pub static ref PYTHON_LOCATION: String =
|
||||
env::var("PYTHON_LOCATION").unwrap_or_else(|_| "venv/bin/python3".to_string());
|
||||
pub static ref STRINGS_TABLE: String =
|
||||
env::var("STRINGS_TABLE").unwrap_or_else(|_| "strings".to_string());
|
||||
pub static ref DEFAULT_PREFIX: String =
|
||||
env::var("DEFAULT_PREFIX").unwrap_or_else(|_| "$".to_string());
|
||||
pub static ref THEME_COLOR: u32 = env::var("THEME_COLOR").map_or(
|
||||
|
@ -290,7 +290,7 @@ impl RegexFramework {
|
||||
|
||||
enum PermissionCheck {
|
||||
None, // No permissions
|
||||
Basic, // Send + Embed permissions (sufficient to reply)
|
||||
Basic(bool, bool), // Send + Embed permissions (sufficient to reply)
|
||||
All, // Above + Manage Webhooks (sufficient to operate)
|
||||
}
|
||||
|
||||
@ -305,15 +305,18 @@ impl Framework for RegexFramework {
|
||||
let user_id = ctx.cache.current_user_id().await;
|
||||
|
||||
let guild_perms = guild.member_permissions(&ctx, user_id).await?;
|
||||
let perms = channel.permissions_for_user(ctx, user_id).await?;
|
||||
let channel_perms = channel.permissions_for_user(ctx, user_id).await?;
|
||||
|
||||
let basic_perms = perms.send_messages();
|
||||
let basic_perms = channel_perms.send_messages();
|
||||
|
||||
Ok(
|
||||
if basic_perms && guild_perms.manage_webhooks() && perms.embed_links() {
|
||||
if basic_perms && guild_perms.manage_webhooks() && channel_perms.embed_links() {
|
||||
PermissionCheck::All
|
||||
} else if basic_perms {
|
||||
PermissionCheck::Basic
|
||||
PermissionCheck::Basic(
|
||||
guild_perms.manage_webhooks(),
|
||||
channel_perms.embed_links(),
|
||||
)
|
||||
} else {
|
||||
PermissionCheck::None
|
||||
},
|
||||
@ -424,11 +427,20 @@ impl Framework for RegexFramework {
|
||||
}
|
||||
}
|
||||
|
||||
PermissionCheck::Basic => {
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.say(&ctx, user_data.response(&pool, "no_perms_general").await)
|
||||
.await;
|
||||
PermissionCheck::Basic(manage_webhooks, embed_links) => {
|
||||
let response = user_data
|
||||
.response(&pool, "no_perms_general")
|
||||
.await
|
||||
.replace(
|
||||
"{manage_webhooks}",
|
||||
if manage_webhooks { "✅" } else { "❌" },
|
||||
)
|
||||
.replace(
|
||||
"{embed_links}",
|
||||
if embed_links { "✅" } else { "❌" },
|
||||
);
|
||||
|
||||
let _ = msg.channel_id.say(&ctx, response).await;
|
||||
}
|
||||
|
||||
PermissionCheck::None => {
|
||||
|
@ -23,10 +23,7 @@ use serenity::{
|
||||
utils::shard_id,
|
||||
};
|
||||
|
||||
use sqlx::{
|
||||
mysql::{MySqlConnection, MySqlPool},
|
||||
Pool,
|
||||
};
|
||||
use sqlx::mysql::MySqlPool;
|
||||
|
||||
use dotenv::dotenv;
|
||||
|
||||
@ -45,7 +42,7 @@ use log::info;
|
||||
struct SQLPool;
|
||||
|
||||
impl TypeMapKey for SQLPool {
|
||||
type Value = Pool<MySqlConnection>;
|
||||
type Value = MySqlPool;
|
||||
}
|
||||
|
||||
struct ReqwestClient;
|
||||
@ -226,7 +223,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
.expect("Error occurred creating client");
|
||||
|
||||
{
|
||||
let pool = MySqlPool::new(
|
||||
let pool = MySqlPool::connect(
|
||||
&env::var("DATABASE_URL").expect("Missing DATABASE_URL from environment"),
|
||||
)
|
||||
.await
|
||||
|
@ -3,14 +3,14 @@ use serenity::{
|
||||
model::{channel::Channel, guild::Guild, id::GuildId, user::User},
|
||||
};
|
||||
|
||||
use sqlx::{Cursor, MySqlPool, Row};
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
use chrono_tz::Tz;
|
||||
|
||||
use log::error;
|
||||
|
||||
use crate::consts::{DEFAULT_PREFIX, LOCAL_LANGUAGE, LOCAL_TIMEZONE, STRINGS_TABLE};
|
||||
use crate::consts::{DEFAULT_PREFIX, LOCAL_LANGUAGE, LOCAL_TIMEZONE};
|
||||
|
||||
pub struct GuildData {
|
||||
pub id: u32,
|
||||
@ -267,27 +267,24 @@ UPDATE users SET name = ?, language = ?, timezone = ? WHERE id = ?
|
||||
}
|
||||
|
||||
pub async fn response(&self, pool: &MySqlPool, name: &str) -> String {
|
||||
let query_str = &format!(
|
||||
struct StringRow {
|
||||
value: String,
|
||||
}
|
||||
|
||||
sqlx::query_as!(
|
||||
StringRow,
|
||||
"
|
||||
SELECT value FROM {} WHERE (language = ? OR language = ?) AND name = ? ORDER BY language = ?
|
||||
SELECT value FROM strings WHERE (language = ? OR language = ?) AND name = ? ORDER BY language = ?
|
||||
",
|
||||
*STRINGS_TABLE
|
||||
);
|
||||
|
||||
let mut query = sqlx::query(&query_str)
|
||||
.bind(&self.language)
|
||||
.bind(&*LOCAL_LANGUAGE)
|
||||
.bind(name)
|
||||
.bind(&*LOCAL_LANGUAGE)
|
||||
.fetch(pool);
|
||||
|
||||
let row = query
|
||||
.next()
|
||||
self.language,
|
||||
&*LOCAL_LANGUAGE,
|
||||
name,
|
||||
&*LOCAL_LANGUAGE
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.unwrap_or_else(|e| panic!("Database error: {:?}", e))
|
||||
.unwrap_or_else(|| panic!("No string with that name: {}", name));
|
||||
|
||||
row.get::<String, &str>("value").clone()
|
||||
.unwrap()
|
||||
.value
|
||||
}
|
||||
|
||||
pub fn timezone(&self) -> Tz {
|
||||
|
Loading…
Reference in New Issue
Block a user