fix regex

This commit is contained in:
2022-02-19 14:28:07 +05:30
parent d20326a846
commit cffeff4e27
4 changed files with 74 additions and 38 deletions

View File

@@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
tracing = "*"
regex = "*"
regex = "1"
tokio-postgres = "*"
rand = "*"

View File

@@ -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:

View File

@@ -8,30 +8,55 @@
};
outputs = { self, nixpkgs, utils, rust-overlay }:
utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
in
{
devShell = with pkgs; mkShell {
buildInputs = [
rust-bin.nightly.latest.default
rust-analyzer
];
};
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
pname = "singh3";
version = "0.1.0";
src = ./. ;
nativeBuildInputs = with pkgs; [
rust-bin.nightly.latest.default
];
cargoSha256 = "sha256-04yTexSkFpa3KQKVvfi7NM1j4V7m08kHDqw98bxXT5M=";
};
}
);
utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
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
{
buildInputs = [
rust-bin.nightly.latest.default
rust-analyzer
];
};
};
devShell = devShells.default;
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
pname = "singh3";
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
rust-bin.nightly.latest.default
];
cargoSha256 = "sha256-04yTexSkFpa3KQKVvfi7NM1j4V7m08kHDqw98bxXT5M=";
};
}
);
}

View File

@@ -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], &reg.to_string(), &msg.author.id.to_string()],
)
.await?;
msg.reply(ctx, "Added").await?;