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