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(); let guild = ctx.guild().unwrap();
if channel.as_ref().map_or(false, |c| c.is_text_based()) { ctx.say(
ctx.say("The channel specified is not a voice channel.") play_from_query(
.await?; &ctx.serenity_context(),
} else { &ctx.data(),
ctx.say( guild,
play_from_query( ctx.author().id,
&ctx.serenity_context(), channel.map(|c| c.id),
&ctx.data(), &name,
guild, false,
ctx.author().id,
channel.map(|c| c.id),
&name,
false,
)
.await,
) )
.await?; .await,
} )
.await?;
Ok(()) Ok(())
} }

View File

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