Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tori)!: add support for beta.tori.fi #40

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
813 changes: 461 additions & 352 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "torimies-rs"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Luukas Pörtfors <lajp@iki.fi>"]

Expand All @@ -26,7 +26,7 @@ version = "1.13"
features = ["macros", "rt-multi-thread", "signal"]

[dependencies.diesel]
version = "1.4.8"
version = "2"
features = ["sqlite", "r2d2"]

[dependencies.openssl]
Expand All @@ -51,14 +51,16 @@ dotenv = "0.15"
futures = "0.3"
chrono = "0.4"
clokwerk = "0.3"
serde_json = "1.0"
serde = "1.0.166"
lazy_static = "1.4"
serde_json = "1"
serde = "1"
async-trait = "0.1"
thiserror = "1"
dashmap = "5.4.0"
itertools = "0.10.5"
r2d2 = "0.8.10"
url = "2.4.0"
encoding = "0.2.33"
hex = "0.4.3"
hmac = "0.12.1"
sha2 = "0.10.8"
base64 = "0.22.0"
tokio-util = "0.7.10"
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ The bot has two main commands implemented as application commands (slash-command
and those are:
* `/vahti url` Adds a new vahti with the specified url
* `/poistavahti url` Removes the vahti with the specified url
* `/poistaesto` Prompts you with a drop-down menu to select which seller you wish to unblock


One additional owner-restricted commmand is also included (this is not a slash-command):
Expand Down
3 changes: 3 additions & 0 deletions migrations/2024-03-31-130704_tori-beta/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
ALTER TABLE Vahdit
DROP COLUMN key;
3 changes: 3 additions & 0 deletions migrations/2024-03-31-130704_tori-beta/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE Vahdit
ADD COLUMN key TEXT;
6 changes: 6 additions & 0 deletions migrations/2024-06-08-111427_new_api/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file should undo anything in `up.sql`
CREATE TABLE Blacklists(
id INTEGER PRIMARY KEY NOT NULL,
user_id INTEGER NOT NULL,
seller_id INTEGER NOT NULL
);
2 changes: 2 additions & 0 deletions migrations/2024-06-08-111427_new_api/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
DROP TABLE Blacklists;
97 changes: 0 additions & 97 deletions src/command/discord/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub async fn handle_interaction(ctx: Context, interaction: Interaction) {
let content = match command.data.name.as_str() {
"vahti" => super::vahti::run(&ctx, &command).await,
"poistavahti" => super::poistavahti::run(&ctx, &command).await,
"poistaesto" => super::poistaesto::run(&ctx, &command).await,
_ => unreachable!(),
};

Expand Down Expand Up @@ -73,79 +72,6 @@ pub async fn handle_interaction(ctx: Context, interaction: Interaction) {
)
.await.unwrap();
}
} else if button.data.custom_id == "block_seller" {
button.defer_ephemeral(&ctx.http).await.unwrap();
let message = button.message.clone();

let urls: Vec<_> = message
.embeds
.iter()
.filter_map(|e| e.footer.as_ref().map(|f| f.text.clone()))
.collect();

assert!(!urls.is_empty(), "Cannot determine search url");

let sellers = message
.embeds
.iter()
.map(|e| e.fields.iter().find(|f| f.name == "Myyjä"))
.filter_map(|f| f.map(|ff| ff.value.clone()))
.filter_map(|s| match s {
#[cfg(feature = "tori")]
_ if s.contains("https://www.tori.fi/li?&aid=") => Some((
s[1..s.find(']').unwrap()].to_string(),
format!(
"{},{}",
&s[s.rfind('=').unwrap() + 1..s.find(')').unwrap()],
crate::tori::ID
),
)),
#[cfg(feature = "huutonet")]
_ if s.contains("https://www.huuto.net/kayttaja/") => Some((
s[1..s.find(']').unwrap()].to_string(),
format!(
"{},{}",
&s[s.rfind('/').unwrap() + 1..s.find(')').unwrap()],
crate::huutonet::ID
),
)),
_ => None,
})
.unique()
.collect::<Vec<_>>();

button
.edit_response(
&ctx.http,
EditInteractionResponse::new()
.content("Choose the seller to block")
.components(menu_from_options("block_seller_menu", sellers)),
)
.await
.unwrap();
} else if button.data.custom_id == "unblock_seller" {
button.defer_ephemeral(&ctx.http).await.unwrap();
let db = ctx.get_db().await.unwrap();
let userid = u64::from(button.user.id);
let ids: Vec<String> = match button.data.kind.clone() {
ComponentInteractionDataKind::StringSelect { values } => {
values[0].split(',').map(|s| s.to_string()).collect()
}
_ => unreachable!(),
};
let sellerid = ids[0].parse::<i32>().unwrap();
let siteid = ids[1].parse::<i32>().unwrap();

db.remove_seller_from_blacklist(userid.try_into().unwrap(), sellerid, siteid)
.await
.unwrap();
button
.edit_response(
&ctx.http,
EditInteractionResponse::new().content("Esto poistettu!"),
)
.await
.unwrap();
} else if button.data.custom_id == "remove_vahti_menu" {
button.defer_ephemeral(&ctx.http).await.unwrap();
let userid = u64::from(button.user.id);
Expand Down Expand Up @@ -190,29 +116,6 @@ pub async fn handle_interaction(ctx: Context, interaction: Interaction) {
.await
.unwrap();
return;
} else if button.data.custom_id == "block_seller_menu" {
button.defer_ephemeral(&ctx.http).await.unwrap();
let db = ctx.get_db().await.unwrap();
let userid = u64::from(button.user.id);
let ids: Vec<String> = match button.data.kind.clone() {
ComponentInteractionDataKind::StringSelect { values } => {
values[0].split(',').map(|s| s.to_string()).collect()
}
_ => unreachable!(),
};
let sellerid = ids[0].parse::<i32>().unwrap();
let siteid = ids[1].parse::<i32>().unwrap();

db.add_seller_to_blacklist(userid as i64, sellerid, siteid)
.await
.unwrap();
button
.edit_response(
&ctx.http,
EditInteractionResponse::new().content("Myyjä estetty!"),
)
.await
.unwrap();
}
}
_ => {}
Expand Down
9 changes: 1 addition & 8 deletions src/command/discord/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
mod extensions;
mod interaction;
mod poistaesto;
mod poistavahti;
mod vahti;

use std::sync::Arc;

use async_trait::async_trait;
use serenity::gateway::ShardManager;
use serenity::model::application::Interaction;
use serenity::model::gateway::GatewayIntents;
use serenity::model::prelude::*;
use serenity::prelude::*;

Expand All @@ -31,11 +28,7 @@ impl EventHandler for Handler {
info!("Connected as {}", ready.user.name);
let _ = serenity::model::application::Command::set_global_commands(
&ctx.http,
vec![
vahti::register(),
poistavahti::register(),
poistaesto::register(),
],
vec![vahti::register(), poistavahti::register()],
)
.await;
}
Expand Down
48 changes: 0 additions & 48 deletions src/command/discord/poistaesto.rs

This file was deleted.

Loading