From 5779f54f2db43ee8d49bc9919ac8f3cfd2799188 Mon Sep 17 00:00:00 2001 From: natto1784 Date: Fri, 25 Feb 2022 21:33:35 +0530 Subject: [PATCH] see count for other users as well --- ci/pipeline.yml | 8 ++++---- flake.nix | 2 +- src/commands/count.rs | 34 +++++++++++++++++++++++++++------- src/commands/tags.rs | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 9304585..7c1e0ab 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -33,7 +33,7 @@ resources: uri: https://git.weirdnatto.in/natto1784/singh3.git branch: master -- name: rust-latest-image +- name: rust-image type: registry-image icon: docker source: @@ -53,10 +53,10 @@ jobs: - get: repo trigger: true passed: [configure-self] - - get: rust-latest-image + - get: rust-image trigger: false - task: format - image: rust-latest-image + image: rust-image config: inputs: - name: repo @@ -70,7 +70,7 @@ jobs: cargo fmt dir: repo - task: build - image: rust-latest-image + image: rust-image config: params: CARGO_HOME: cargo-home diff --git a/flake.nix b/flake.nix index 60ce66c..ad9adc2 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A simple filehost written in rust"; + description = "singh3 discord bot"; inputs = { nixpkgs.url = github:nixos/nixpkgs/nixos-unstable; diff --git a/src/commands/count.rs b/src/commands/count.rs index 5b09251..6fcb08b 100644 --- a/src/commands/count.rs +++ b/src/commands/count.rs @@ -14,19 +14,39 @@ use tokio_postgres::Row; #[command] #[aliases("kitna", "c")] -pub async fn count(ctx: &Context, msg: &Message, args: Args) -> CommandResult { - let query: String = args.raw().collect::>().join(" "); - if query == "" { - msg.reply(ctx, "Count what?").await?; +pub async fn count(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { + if args.len() > 2 || args.len() == 0 { + msg.reply(ctx, "Please use `,count `").await?; return Ok(()); } + + let query = args.single::().unwrap(); + let user = if args.len() == 2 { + let user = args.single::(); + match user { + Ok(id) => match id.to_user(&ctx.http).await { + Ok(u) => u, + Err(_) => { + msg.reply(ctx, "No such user").await?; + return Ok(()); + } + }, + Err(_) => { + msg.reply(ctx, "No such user").await?; + return Ok(()); + } + } + } else { + msg.author.clone() + }; + let data_read = ctx.data.read().await; let db = data_read .get::() .expect("Expected Database in TypeMap.") .clone(); - let id = msg.author.id.to_string(); + let id = user.id.to_string(); let mut query_helper = db .query("SELECT name FROM words WHERE $1 ~ reg", &[&query]) .await?; @@ -60,12 +80,12 @@ pub async fn count(ctx: &Context, msg: &Message, args: Args) -> CommandResult { &[&name], ) .await?; - let query_result = if count_query.is_empty() { + let query_result: i32 = if count_query.is_empty() { 0 } else { count_query[0].get(0) }; - reply += &format!("\n{} count for you: {}", name, query_result); + reply += &format!("\n{} count for {}: {}", name, user.name, query_result); } msg.reply(ctx, reply).await?; Ok(()) diff --git a/src/commands/tags.rs b/src/commands/tags.rs index 1cc167d..ed08ee6 100644 --- a/src/commands/tags.rs +++ b/src/commands/tags.rs @@ -3,7 +3,7 @@ use core::time::Duration; use serenity::{ builder::CreateEmbed, collector::component_interaction_collector::ComponentInteractionCollectorBuilder, - framework::standard::{macros::command, Args, CommandResult, Delimiter}, + framework::standard::{macros::command, Args, CommandResult}, futures::StreamExt, model::{interactions::InteractionResponseType, prelude::*}, prelude::*,