Skip to content

Commit

Permalink
Expose list of registered bot users (#4919)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 4, 2023
1 parent 416d444 commit eac89bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions backend/canisters/user_index/impl/src/queries/http_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, u32> = BTreeMap::new();
for user in state.data.users.iter().filter(|u| u.date_created > 0) {
Expand All @@ -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(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u128>();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit eac89bc

Please sign in to comment.