Remove broken is_text_based check

This commit is contained in:
jude 2023-10-21 17:06:41 +01:00
parent 8390bf0ec6
commit 6d324e10cb
2 changed files with 117 additions and 138 deletions

View File

@ -25,24 +25,19 @@ pub async fn play(
let guild = ctx.guild().unwrap();
if channel.as_ref().map_or(false, |c| c.is_text_based()) {
ctx.say("The channel specified is not a voice channel.")
.await?;
} else {
ctx.say(
play_from_query(
&ctx.serenity_context(),
&ctx.data(),
guild,
ctx.author().id,
channel.map(|c| c.id),
&name,
false,
)
.await,
ctx.say(
play_from_query(
&ctx.serenity_context(),
&ctx.data(),
guild,
ctx.author().id,
channel.map(|c| c.id),
&name,
false,
)
.await?;
}
.await,
)
.await?;
Ok(())
}

View File

@ -99,14 +99,13 @@ impl SoundCtx for Data {
let sound = sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE id = ? AND (
public = 1 OR
uploader_id = ? OR
server_id = ?
)
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE id = ? AND (
public = 1 OR
uploader_id = ? OR
server_id = ?
)",
id,
user_id,
guild_id
@ -123,24 +122,23 @@ SELECT name, id, public, server_id, uploader_id
sound = sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name = ? AND (
public = 1 OR
uploader_id = ? OR
server_id = ?
)
ORDER BY
uploader_id = ? DESC,
EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
) DESC,
server_id = ? DESC,
public = 1 DESC,
rand()
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name = ? AND (
public = 1 OR
uploader_id = ? OR
server_id = ?
)
ORDER BY
uploader_id = ? DESC,
EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
) DESC,
server_id = ? DESC,
public = 1 DESC,
rand()",
name,
user_id,
guild_id,
@ -154,24 +152,23 @@ SELECT name, id, public, server_id, uploader_id
sound = sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name LIKE CONCAT('%', ?, '%') AND (
public = 1 OR
uploader_id = ? OR
server_id = ?
)
ORDER BY
uploader_id = ? DESC,
EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
) DESC,
server_id = ? DESC,
public = 1 DESC,
rand()
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name LIKE CONCAT('%', ?, '%') AND (
public = 1 OR
uploader_id = ? OR
server_id = ?
)
ORDER BY
uploader_id = ? DESC,
EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
) DESC,
server_id = ? DESC,
public = 1 DESC,
rand()",
name,
user_id,
guild_id,
@ -199,15 +196,14 @@ SELECT name, id, public, server_id, uploader_id
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name LIKE CONCAT(?, '%') AND (uploader_id = ? OR server_id = ? OR EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
))
LIMIT 25
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name LIKE CONCAT(?, '%') AND (uploader_id = ? OR server_id = ? OR EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
))
LIMIT 25",
query,
user_id,
guild_id.into(),
@ -227,15 +223,14 @@ LIMIT 25
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name LIKE CONCAT(?, '%') AND EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
)
LIMIT 25
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE name LIKE CONCAT(?, '%') AND EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
)
LIMIT 25",
query,
user_id.into(),
)
@ -253,12 +248,11 @@ LIMIT 25
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE uploader_id = ?
ORDER BY id DESC
LIMIT ?, ?
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE uploader_id = ?
ORDER BY id DESC
LIMIT ?, ?",
user_id.into(),
page * 25,
(page + 1) * 25
@ -270,11 +264,10 @@ SELECT name, id, public, server_id, uploader_id
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE uploader_id = ?
ORDER BY id DESC
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE uploader_id = ?
ORDER BY id DESC",
user_id.into()
)
.fetch_all(&self.database)
@ -295,13 +288,12 @@ SELECT name, id, public, server_id, uploader_id
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
INNER JOIN favorite_sounds f ON sounds.id = f.sound_id
WHERE f.user_id = ?
ORDER BY id DESC
LIMIT ?, ?
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
INNER JOIN favorite_sounds f ON sounds.id = f.sound_id
WHERE f.user_id = ?
ORDER BY id DESC
LIMIT ?, ?",
user_id.into(),
page * 25,
(page + 1) * 25
@ -313,12 +305,11 @@ SELECT name, id, public, server_id, uploader_id
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
INNER JOIN favorite_sounds f ON sounds.id = f.sound_id
WHERE f.user_id = ?
ORDER BY id DESC
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
INNER JOIN favorite_sounds f ON sounds.id = f.sound_id
WHERE f.user_id = ?
ORDER BY id DESC",
user_id.into()
)
.fetch_all(&self.database)
@ -339,12 +330,11 @@ SELECT name, id, public, server_id, uploader_id
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE server_id = ?
ORDER BY id DESC
LIMIT ?, ?
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE server_id = ?
ORDER BY id DESC
LIMIT ?, ?",
guild_id.into(),
page * 25,
(page + 1) * 25
@ -357,11 +347,10 @@ SELECT name, id, public, server_id, uploader_id
sqlx::query_as_unchecked!(
Sound,
"
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE server_id = ?
ORDER BY id DESC
",
SELECT name, id, public, server_id, uploader_id
FROM sounds
WHERE server_id = ?
ORDER BY id DESC",
guild_id.into()
)
.fetch_all(&self.database)
@ -418,11 +407,10 @@ impl Sound {
let record = sqlx::query_as_unchecked!(
Src,
"
SELECT src
FROM sounds
WHERE id = ?
LIMIT 1
",
SELECT src
FROM sounds
WHERE id = ?
LIMIT 1",
self.id
)
.fetch_one(db_pool)
@ -469,10 +457,9 @@ SELECT src
let c = sqlx::query!(
"
SELECT COUNT(1) as count
FROM sounds
WHERE uploader_id = ?
",
SELECT COUNT(1) as count
FROM sounds
WHERE uploader_id = ?",
user_id
)
.fetch_one(db_pool)
@ -491,12 +478,11 @@ SELECT COUNT(1) as count
let c = sqlx::query!(
"
SELECT COUNT(1) as count
FROM sounds
WHERE
uploader_id = ? AND
name = ?
",
SELECT COUNT(1) as count
FROM sounds
WHERE
uploader_id = ? AND
name = ?",
user_id,
name
)
@ -513,12 +499,11 @@ SELECT COUNT(1) as count
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
sqlx::query!(
"
UPDATE sounds
SET
public = ?
WHERE
id = ?
",
UPDATE sounds
SET
public = ?
WHERE
id = ?",
self.public,
self.id
)
@ -619,9 +604,8 @@ WHERE
Some(data) => {
match sqlx::query!(
"
INSERT INTO sounds (name, server_id, uploader_id, public, src)
VALUES (?, ?, ?, 1, ?)
",
INSERT INTO sounds (name, server_id, uploader_id, public, src)
VALUES (?, ?, ?, 1, ?)",
name,
server_id,
user_id,