see count for other users as well

This commit is contained in:
2022-02-25 21:33:35 +05:30
parent 1d63fc050c
commit 5779f54f2d
4 changed files with 33 additions and 13 deletions

View File

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

View File

@@ -1,5 +1,5 @@
{
description = "A simple filehost written in rust";
description = "singh3 discord bot";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;

View File

@@ -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::<Vec<&str>>().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 <word> <user>`").await?;
return Ok(());
}
let query = args.single::<String>().unwrap();
let user = if args.len() == 2 {
let user = args.single::<UserId>();
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::<crate::Database>()
.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(())

View File

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