fix regex
This commit is contained in:
@@ -6,7 +6,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "*"
|
tracing = "*"
|
||||||
regex = "*"
|
regex = "1"
|
||||||
tokio-postgres = "*"
|
tokio-postgres = "*"
|
||||||
rand = "*"
|
rand = "*"
|
||||||
|
|
||||||
|
@@ -56,11 +56,19 @@ jobs:
|
|||||||
- get: rust-latest-image
|
- get: rust-latest-image
|
||||||
trigger: false
|
trigger: false
|
||||||
- task: format
|
- task: format
|
||||||
|
image: rust-latest-image
|
||||||
config:
|
config:
|
||||||
|
inputs:
|
||||||
|
- name: singh3-repo
|
||||||
|
platform: linux
|
||||||
run:
|
run:
|
||||||
path: cargo
|
path: sh
|
||||||
args: ["fmt"]
|
args:
|
||||||
dir: singh3-bin
|
- -c
|
||||||
|
- |
|
||||||
|
rustup component add rustfmt
|
||||||
|
cargo fmt
|
||||||
|
dir: singh3-repo
|
||||||
- task: build
|
- task: build
|
||||||
image: rust-latest-image
|
image: rust-latest-image
|
||||||
config:
|
config:
|
||||||
|
27
flake.nix
27
flake.nix
@@ -16,13 +16,38 @@
|
|||||||
inherit system overlays;
|
inherit system overlays;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
rec {
|
||||||
|
devShells = with pkgs; {
|
||||||
|
default = mkShell
|
||||||
|
{
|
||||||
|
buildInputs = [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
rust-analyzer
|
||||||
|
postgresql
|
||||||
|
];
|
||||||
|
};
|
||||||
|
withDB = mkShell
|
||||||
|
{
|
||||||
|
buildInputs = [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
postgresql
|
||||||
|
];
|
||||||
|
};
|
||||||
|
bare = mkShell
|
||||||
|
{
|
||||||
|
buildInputs = [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
withLSP = mkShell
|
||||||
{
|
{
|
||||||
devShell = with pkgs; mkShell {
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
rust-bin.nightly.latest.default
|
rust-bin.nightly.latest.default
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
devShell = devShells.default;
|
||||||
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
|
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
|
||||||
pname = "singh3";
|
pname = "singh3";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
use crate::lib::components::make_terminal_components;
|
use crate::lib::components::make_terminal_components;
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
use regex::Regex;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
builder::CreateEmbed,
|
builder::CreateEmbed,
|
||||||
collector::component_interaction_collector::ComponentInteractionCollectorBuilder,
|
collector::component_interaction_collector::ComponentInteractionCollectorBuilder,
|
||||||
@@ -79,15 +80,21 @@ pub async fn cadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if queries[1].contains(" ") {
|
let r = Regex::new(&format!("(?i){}", queries[1]));
|
||||||
msg.reply(ctx, "Not a valid regex").await?;
|
|
||||||
|
if r.is_err() {
|
||||||
|
msg.reply(ctx, "Please enter a valid regex").await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let reg = r.unwrap();
|
||||||
|
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
let db = data_read
|
let db = data_read
|
||||||
.get::<crate::Database>()
|
.get::<crate::Database>()
|
||||||
.expect("Expected Database in TypeMap.")
|
.expect("Expected Database in TypeMap.")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let check_existense = db
|
let check_existense = db
|
||||||
.query("SELECT name, reg FROM words WHERE name=$1", &[&queries[0]])
|
.query("SELECT name, reg FROM words WHERE name=$1", &[&queries[0]])
|
||||||
.await?;
|
.await?;
|
||||||
@@ -102,11 +109,7 @@ pub async fn cadd(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||||||
}
|
}
|
||||||
db.execute(
|
db.execute(
|
||||||
"INSERT INTO words(name, reg, owner) VALUES($1, $2, $3)",
|
"INSERT INTO words(name, reg, owner) VALUES($1, $2, $3)",
|
||||||
&[
|
&[&queries[0], ®.to_string(), &msg.author.id.to_string()],
|
||||||
&queries[0],
|
|
||||||
&("(?i)".to_string() + queries[1]),
|
|
||||||
&msg.author.id.to_string(),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
msg.reply(ctx, "Added").await?;
|
msg.reply(ctx, "Added").await?;
|
||||||
|
Reference in New Issue
Block a user