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

Upgrade to 2.0 #24

Merged
merged 2 commits into from
Sep 20, 2024
Merged
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
1,423 changes: 893 additions & 530 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[package]
name = "surreal_bot"
version = "0.5.1"
version = "0.6.0"
edition = "2021"
authors = [
"Raphael Darley <[email protected]>",
"alyti <[email protected]>",
]

[dependencies]
anyhow = "1.0.71"
anyhow = "1.0.89"
cargo-lock = "9.0.0"
async-channel = "2.1.1"
dotenv = "0.15.0"
async-channel = "2.3.1"
dotenvy = "0.15.7"
humantime = "2.1.0"
memorable-wordlist = "0.1.7"
once_cell = "1.18.0"
serde = "1.0.166"
serde_json = "1.0.100"
serde = "1.0.210"
serde_json = "1.0.128"
serenity = { default-features = false, features = [
"client",
"gateway",
"model",
"rustls_backend",
], version = "0.11.6" }
surrealdb = { version = "1.5.3", features = ["kv-mem", "kv-rocksdb"] }
tokio = { version = "1.29.1", features = [
surrealdb = { version = "2.0.1", features = ["kv-mem", "kv-rocksdb"] }
tokio = { version = "1.40.0", features = [
"macros",
"signal",
"rt-multi-thread",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serenity::{
model::prelude::{application_command::CommandDataOption, *},
prelude::*,
};
use surrealdb::opt::auth::{Database, Namespace, Root, Scope};
use surrealdb::opt::auth::{Database, Namespace, Root};
use tokio::time::Instant;

use crate::{
Expand Down
16 changes: 16 additions & 0 deletions src/commands/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ pub async fn run(

let channel = command.channel_id.to_channel(&ctx).await?.guild().unwrap();

let Some(parent) = channel.parent_id else {
return CmdError::UnsupportedChannelConnect
.reply(&ctx, command)
.await;
};

let parent = parent.to_channel(&ctx).await?;

if let Some(category) = parent.category() {
if category.id != config.active_channel && category.id != config.archive_channel {
return CmdError::UnsupportedChannelConnect
.reply(&ctx, command)
.await;
}
}

let db = create_db_instance(&config).await?;

register_db(
Expand Down
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod auth;
// pub mod auth;
pub mod clean;
pub mod clean_all;
pub mod config_update;
Expand All @@ -18,7 +18,7 @@ use serenity::builder::CreateApplicationCommands;

pub fn register_all(commands: &mut CreateApplicationCommands) -> &mut CreateApplicationCommands {
commands
.create_application_command(|command| auth::register(command))
// .create_application_command(|command| auth::register(command))
.create_application_command(|command| create::register(command))
.create_application_command(|command| configure::register(command))
.create_application_command(|command| share::register(command))
Expand Down
2 changes: 1 addition & 1 deletion src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl EventHandler for Handler {
async {
trace!(command = ?command, "received command interaction");
let res = match command.data.name.as_str() {
"auth" => commands::auth::run(&command, ctx.clone()).await,
// "auth" => commands::auth::run(&command, ctx.clone()).await,
"create" => commands::create::run(&command, ctx.clone()).await,
"configure" => commands::configure::run(&command, ctx.clone()).await,
"share" => commands::share::run(&command, ctx.clone()).await,
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use serenity::{
},
prelude::Context,
};
use surrealdb::{opt::IntoQuery, sql::Value, Error, Response};
use surrealdb::{opt::IntoQuery, sql, Error, Response};
use tokio::sync::Mutex;
use tokio::time::{Duration, Instant};
use utils::{ephemeral_interaction_edit, CmdError, ToInteraction, MAX_FILE_SIZE};
Expand Down Expand Up @@ -328,16 +328,16 @@ pub fn process(
let num_statements = response.num_statements();
// Prepare a single value from the query response
let value = if num_statements > 1 {
let mut output = Vec::<Value>::with_capacity(num_statements);
let mut output = Vec::<sql::Value>::with_capacity(num_statements);
for index in 0..num_statements {
output.push(match response.take(index) {
Ok(v) => v,
Err(e) => e.to_string().into(),
output.push(match response.take::<surrealdb::Value>(index) {
Ok(v) => v.into_inner(),
Err(e) => sql::Value::from(e.to_string()),
});
}
Value::from(output)
sql::Value::from(output)
} else {
response.take(0)?
response.take::<surrealdb::Value>(0)?.into_inner()
};
// Check if we should emit JSON and/or prettify
Ok(match (json, pretty) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serenity::model::prelude::*;
use serenity::prelude::*;

use dotenv::dotenv;
use dotenvy::dotenv;
use std::env;
use std::path::Path;
use surreal_bot::config::Config;
Expand Down
7 changes: 6 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub enum CmdError {
ExpectedAttachment,
CreateDB(anyhow::Error),
RegisterDB(anyhow::Error),
UnsupportedChannelConnect,
}

impl CmdError {
Expand Down Expand Up @@ -149,7 +150,11 @@ impl CmdError {
CmdError::RegisterDB(e) => (
"Database registration failed".into(),
format!("There was an error while registering the database:\n```rust\n{e}\n```").into(),
)
),
CmdError::UnsupportedChannelConnect => (
"Tried to connect on an unsupported channel".into(),
"Please use /create or switch to a thread or SurrealQL channel".into()
),
}
}

Expand Down
Loading