Skip to content

Commit

Permalink
add trash reason to /utils trash
Browse files Browse the repository at this point in the history
  • Loading branch information
circuitsacul committed Jan 6, 2023
1 parent c41f95f commit b12f0b3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 114 deletions.
181 changes: 70 additions & 111 deletions sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -584,75 +584,6 @@
},
"query": "INSERT INTO autostar_channels\n (name, channel_id, guild_id)\n VALUES ($1, $2, $3)\n RETURNING *"
},
"24c0b13bf1b89576a41366dbe335c7425de871a8de48808ccde254394d345bb0": {
"describe": {
"columns": [
{
"name": "message_id",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "guild_id",
"ordinal": 1,
"type_info": "Int8"
},
{
"name": "channel_id",
"ordinal": 2,
"type_info": "Int8"
},
{
"name": "author_id",
"ordinal": 3,
"type_info": "Int8"
},
{
"name": "is_nsfw",
"ordinal": 4,
"type_info": "Bool"
},
{
"name": "forced_to",
"ordinal": 5,
"type_info": "Int4Array"
},
{
"name": "trashed",
"ordinal": 6,
"type_info": "Bool"
},
{
"name": "trash_reason",
"ordinal": 7,
"type_info": "Varchar"
},
{
"name": "frozen",
"ordinal": 8,
"type_info": "Bool"
}
],
"nullable": [
false,
false,
false,
false,
false,
false,
false,
true,
false
],
"parameters": {
"Left": [
"Bool",
"Int8"
]
}
},
"query": "UPDATE messages SET trashed=$1 WHERE message_id=$2 RETURNING *"
},
"26ba63804320b440dba9096dedb959767348c0ad53144f02220af3f7255cb5d6": {
"describe": {
"columns": [
Expand Down Expand Up @@ -2205,27 +2136,6 @@
},
"query": "INSERT INTO posroles\n (role_id, guild_id)\n VALUES ($1, $2)\n RETURNING *"
},
"7b137ea29ecca19db96e259ed6b24d8a0f3fa5a3cb493c6e6be0b2bf54979e90": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1\n AND target_author_id=$2 AND is_downvote=true"
},
"7e14b14e400319e69ca7b7a581257ee46e1b60ee05872f90474bc3c107a47e08": {
"describe": {
"columns": [
Expand Down Expand Up @@ -3181,6 +3091,76 @@
},
"query": "SELECT * FROM permroles WHERE guild_id=$1"
},
"ba8149792574e9b60c34327a9444485f28b367c243ed9142d6ee3ea1ce77d879": {
"describe": {
"columns": [
{
"name": "message_id",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "guild_id",
"ordinal": 1,
"type_info": "Int8"
},
{
"name": "channel_id",
"ordinal": 2,
"type_info": "Int8"
},
{
"name": "author_id",
"ordinal": 3,
"type_info": "Int8"
},
{
"name": "is_nsfw",
"ordinal": 4,
"type_info": "Bool"
},
{
"name": "forced_to",
"ordinal": 5,
"type_info": "Int4Array"
},
{
"name": "trashed",
"ordinal": 6,
"type_info": "Bool"
},
{
"name": "trash_reason",
"ordinal": 7,
"type_info": "Varchar"
},
{
"name": "frozen",
"ordinal": 8,
"type_info": "Bool"
}
],
"nullable": [
false,
false,
false,
false,
false,
false,
false,
true,
false
],
"parameters": {
"Left": [
"Bool",
"Varchar",
"Int8"
]
}
},
"query": "UPDATE messages SET trashed=$1, trash_reason=$2 WHERE message_id=$3 RETURNING *"
},
"bcbcc0bbec6474d9d1b5928f7b8275bcbf87727fa4f76c69fa99e8de86e891f3": {
"describe": {
"columns": [
Expand Down Expand Up @@ -3598,27 +3578,6 @@
},
"query": "SELECT COUNT(*) as count FROM permroles WHERE guild_id=$1"
},
"d9d12cee8a2062669bf160b9f2a1cb20ee03e5bf5c59436a1a21d6bd2e767c06": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1\n AND target_author_id=$2 AND is_downvote=false"
},
"db47dd094d91342ad83996e3ebe7cacc85c7f77f1e7ecd0c9d8ba6914fb9ec8a": {
"describe": {
"columns": [
Expand Down
4 changes: 3 additions & 1 deletion src/database/models/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ impl Message {
pool: &sqlx::PgPool,
message_id: i64,
trashed: bool,
reason: Option<&str>,
) -> sqlx::Result<Option<Self>> {
sqlx::query_as!(
Self,
"UPDATE messages SET trashed=$1 WHERE message_id=$2 RETURNING *",
"UPDATE messages SET trashed=$1, trash_reason=$2 WHERE message_id=$3 RETURNING *",
trashed,
reason,
message_id,
)
.fetch_optional(pool)
Expand Down
7 changes: 5 additions & 2 deletions src/interactions/commands/chat/utils/trash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use super::INVALID_MESSAGE_ERR;
pub struct Trash {
/// Link to the message to trash.
message: String,

/// Reason for trashing the message.
reason: Option<String>,
}

impl Trash {
Expand All @@ -41,7 +44,7 @@ impl Trash {
return Ok(());
}

Message::set_trashed(&ctx.bot.pool, orig.message_id, true).await?;
Message::set_trashed(&ctx.bot.pool, orig.message_id, true, self.reason.as_deref()).await?;
ctx.respond_str("Message trashed.", true).await?;
RefreshMessage::new(&ctx.bot, orig.message_id.into_id())
.refresh(true)
Expand Down Expand Up @@ -78,7 +81,7 @@ impl UnTrash {
return Ok(());
}

Message::set_trashed(&ctx.bot.pool, orig.message_id, false).await?;
Message::set_trashed(&ctx.bot.pool, orig.message_id, false, None).await?;
ctx.respond_str("Message untrashed.", true).await?;
RefreshMessage::new(&ctx.bot, orig.message_id.into_id())
.refresh(true)
Expand Down

0 comments on commit b12f0b3

Please sign in to comment.