-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/remove bot to/from community (#6991)
- Loading branch information
Showing
12 changed files
with
378 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use candid::CandidType; | ||
use serde::{Deserialize, Serialize}; | ||
use ts_export::ts_export; | ||
use types::{SlashCommandPermissions, UserId}; | ||
|
||
#[ts_export(community, add_bot)] | ||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub struct Args { | ||
pub bot_id: UserId, | ||
pub granted_permissions: SlashCommandPermissions, | ||
} | ||
|
||
#[ts_export(community, add_bot)] | ||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub enum Response { | ||
Success, | ||
CommunityFrozen, | ||
NotAuthorized, | ||
AlreadyAdded, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use candid::CandidType; | ||
use serde::{Deserialize, Serialize}; | ||
use ts_export::ts_export; | ||
use types::UserId; | ||
|
||
#[ts_export(community, remove_bot)] | ||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub struct Args { | ||
pub bot_id: UserId, | ||
} | ||
|
||
#[ts_export(community, remove_bot)] | ||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub enum Response { | ||
Success, | ||
NotAuthorized, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::{activity_notifications::handle_activity_notification, mutate_state, run_regular_jobs, RuntimeState}; | ||
use canister_api_macros::update; | ||
use canister_tracing_macros::trace; | ||
use community_canister::add_bot::{Response::*, *}; | ||
|
||
#[update(msgpack = true)] | ||
#[trace] | ||
fn add_bot(args: Args) -> Response { | ||
run_regular_jobs(); | ||
|
||
mutate_state(|state| add_bot_impl(args, state)) | ||
} | ||
|
||
fn add_bot_impl(args: Args, state: &mut RuntimeState) -> Response { | ||
if state.data.is_frozen() { | ||
return CommunityFrozen; | ||
} | ||
|
||
let caller = state.env.caller(); | ||
|
||
let Some(member) = state.data.members.get(caller) else { | ||
return NotAuthorized; | ||
}; | ||
|
||
if member.suspended().value || !member.role().is_owner() { | ||
return NotAuthorized; | ||
} | ||
|
||
if !state | ||
.data | ||
.add_bot(member.user_id, args.bot_id, args.granted_permissions, state.env.now()) | ||
{ | ||
return AlreadyAdded; | ||
} | ||
|
||
handle_activity_notification(state); | ||
Success | ||
} |
Oops, something went wrong.