diff --git a/backend/canisters/user_index/CHANGELOG.md b/backend/canisters/user_index/CHANGELOG.md index 92da5c30cd..d649cd5011 100644 --- a/backend/canisters/user_index/CHANGELOG.md +++ b/backend/canisters/user_index/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Introduce `Lifetime Diamond Membership` ([#4876](https://github.com/open-chat-labs/open-chat/pull/4876)) - Support updating Diamond membership subscription ([#4884](https://github.com/open-chat-labs/open-chat/pull/4884)) - Add `diamond_membership_status` to `current_user` response ([#4896](https://github.com/open-chat-labs/open-chat/pull/4896)) +- Expose list of registered bot users ([#4919](https://github.com/open-chat-labs/open-chat/pull/4919)) ### Changed diff --git a/backend/canisters/user_index/impl/src/queries/http_request.rs b/backend/canisters/user_index/impl/src/queries/http_request.rs index 01c9688b04..4b73129883 100644 --- a/backend/canisters/user_index/impl/src/queries/http_request.rs +++ b/backend/canisters/user_index/impl/src/queries/http_request.rs @@ -18,6 +18,18 @@ fn http_request(request: HttpRequest) -> HttpResponse { build_json_response(&state.metrics()) } + fn get_bot_users(state: &RuntimeState) -> HttpResponse { + let bots: Vec<_> = state + .data + .users + .iter() + .filter(|u| u.is_bot) + .map(|u| u.user_id.to_string()) + .collect(); + + build_json_response(&bots) + } + fn get_new_users_per_day(state: &RuntimeState) -> HttpResponse { let mut grouped: BTreeMap = BTreeMap::new(); for user in state.data.users.iter().filter(|u| u.date_created > 0) { @@ -32,6 +44,7 @@ fn http_request(request: HttpRequest) -> HttpResponse { Route::Logs(since) => get_logs_impl(since), Route::Traces(since) => get_traces_impl(since), Route::Metrics => read_state(get_metrics_impl), + Route::Other(path, _) if path == "bots" => read_state(get_bot_users), Route::Other(path, _) if path == "new_users_per_day" => read_state(get_new_users_per_day), _ => HttpResponse::not_found(), } diff --git a/backend/integration_tests/src/communities/send_message_tests.rs b/backend/integration_tests/src/communities/send_message_tests.rs index 333a1b1544..6bd843f0fb 100644 --- a/backend/integration_tests/src/communities/send_message_tests.rs +++ b/backend/integration_tests/src/communities/send_message_tests.rs @@ -124,7 +124,7 @@ fn send_prize_in_channel() { channel_id, } = init_test_data(env, canister_ids, *controller); - let inital_user1_balance = balance_of(env, canister_ids.icp_ledger, user1.canister()) as u128; + let initial_user1_balance = balance_of(env, canister_ids.icp_ledger, user1.canister()) as u128; let fee = 10000; let prizes = vec![Tokens::from_e8s(100000)]; let total = prizes.iter().map(|t| (t.e8s() as u128) + fee).sum::(); @@ -168,7 +168,7 @@ fn send_prize_in_channel() { user_canister::send_message_with_transfer_to_channel::Response::Success(_) ) { let user1_balance_after_sending_prize = balance_of(env, canister_ids.icp_ledger, user1.canister()) as u128; - assert_eq!(user1_balance_after_sending_prize, inital_user1_balance - total - fee); + assert_eq!(user1_balance_after_sending_prize, initial_user1_balance - total - fee); let community_balance_after_sending_prize = balance_of(env, canister_ids.icp_ledger, community_id.into()) as u128; assert_eq!(community_balance_after_sending_prize, total); @@ -177,7 +177,7 @@ fn send_prize_in_channel() { tick_many(env, 5); let user1_balance_after_refund = balance_of(env, canister_ids.icp_ledger, user1.canister()) as u128; - assert_eq!(user1_balance_after_refund, inital_user1_balance - 2 * fee); + assert_eq!(user1_balance_after_refund, initial_user1_balance - 2 * fee); let community_balance_after_refund = balance_of(env, canister_ids.icp_ledger, community_id.into()) as u128; assert_eq!(community_balance_after_refund, 0);