mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-23 16:50:49 +00:00
ignore
command (#59)
* New table `ignored_users` and queries * Update sqlx to 0.8 * Implement `ignore` command and add needed hooks
This commit is contained in:
parent
a36fa87964
commit
7c0cbea716
30 changed files with 580 additions and 383 deletions
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n user_id as \"user_id: i64\",\n username,\n id as \"id: i64\",\n preferred_mode as \"preferred_mode: u8\",\n failures as \"failures: u8\"\n FROM osu_users WHERE user_id = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "user_id: i64",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id: i64",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "preferred_mode: u8",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "failures: u8",
|
||||
"ordinal": 4,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "25dcc59341e6375ee6a55aa014aecc54be42e1e8787ae5a06a61bb8ba8e9c366"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n user_id as \"user_id: i64\",\n username,\n id as \"id: i64\",\n preferred_mode as \"preferred_mode: u8\",\n failures as \"failures: u8\"\n FROM osu_users",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "user_id: i64",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id: i64",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "preferred_mode: u8",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "failures: u8",
|
||||
"ordinal": 4,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "54f54f669244fbdf1ad68664290d8f32f0bda74ceee62d10c84ac03b710c828c"
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT\n INTO osu_users(user_id, username, id, preferred_mode, failures)\n VALUES(?, ?, ?, ?, ?)\n ON CONFLICT (user_id) WHERE id = ? DO UPDATE\n SET\n username = excluded.username,\n preferred_mode = excluded.preferred_mode,\n failures = excluded.failures\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 6
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "b9c63ef764711088cfbb58ce2ed1f46e3521357ec1d7c062bef762d3e4267378"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n user_id as \"user_id: i64\",\n username,\n id as \"id: i64\",\n preferred_mode as \"preferred_mode: u8\",\n failures as \"failures: u8\"\n FROM osu_users WHERE id = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "user_id: i64",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id: i64",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "preferred_mode: u8",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "failures: u8",
|
||||
"ordinal": 4,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e313b2e91d0da80a94e9a1030f94cf30b025c9ac0ac4d5bcc12656459c5e083a"
|
||||
}
|
|
@ -10,7 +10,7 @@ workspace = true
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sqlx = { version = "0.7", features = ["runtime-tokio", "sqlite", "chrono"] }
|
||||
sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite", "chrono"] }
|
||||
thiserror = "1.0.31"
|
||||
chrono = "0.4.19"
|
||||
futures-util = "0.3.21"
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
-- Add migration script here
|
||||
|
||||
CREATE TABLE ignored_users (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
ignored_since DATETIME NOT NULL DEFAULT (DATETIME('now'))
|
||||
);
|
60
youmubot-db-sql/src/models/ignore_list.rs
Normal file
60
youmubot-db-sql/src/models/ignore_list.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use super::*;
|
||||
use sqlx::Executor;
|
||||
|
||||
/// An ignored user in the ignored user list.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IgnoredUser {
|
||||
pub id: i64,
|
||||
pub username: String,
|
||||
pub ignored_since: DateTime,
|
||||
}
|
||||
|
||||
impl IgnoredUser {
|
||||
/// Returns a list of all ignored users.
|
||||
pub async fn get_all<'a, E>(conn: E) -> Result<Vec<Self>>
|
||||
where
|
||||
E: Executor<'a, Database = Database>,
|
||||
{
|
||||
Ok(query_as!(
|
||||
IgnoredUser,
|
||||
r#"SELECT
|
||||
id,
|
||||
username,
|
||||
ignored_since as "ignored_since: DateTime"
|
||||
FROM ignored_users
|
||||
ORDER BY id ASC"#
|
||||
)
|
||||
.fetch_all(conn)
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// Add an user to ignore list.
|
||||
pub async fn add<'a, E>(conn: E, user_id: i64, username: String) -> Result<Self>
|
||||
where
|
||||
E: Executor<'a, Database = Database>,
|
||||
{
|
||||
Ok(query_as!(
|
||||
IgnoredUser,
|
||||
r#"INSERT INTO ignored_users(id, username) VALUES (?, ?)
|
||||
ON CONFLICT (id) DO UPDATE SET username = excluded.username
|
||||
RETURNING id,
|
||||
username,
|
||||
ignored_since as "ignored_since: DateTime""#,
|
||||
user_id,
|
||||
username
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await?)
|
||||
}
|
||||
|
||||
// Remove an user from ignore list.
|
||||
pub async fn remove<'a, E>(conn: E, user_id: i64) -> Result<()>
|
||||
where
|
||||
E: Executor<'a, Database = Database>,
|
||||
{
|
||||
query!(r#"DELETE FROM ignored_users WHERE id = ?"#, user_id)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -4,5 +4,6 @@ use sqlx::{query, query_as, Executor};
|
|||
/// The DateTime used in the package.
|
||||
pub type DateTime = chrono::DateTime<chrono::Utc>;
|
||||
|
||||
pub mod ignore_list;
|
||||
pub mod osu;
|
||||
pub mod osu_user;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue