Skip to content

Commit

Permalink
handle incorrect meeting moderator
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Jun 26, 2024
1 parent 21d1aac commit c2622af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
22 changes: 17 additions & 5 deletions src/command/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};

use matrix_sdk::ruma::{events::room::message::RoomMessageEventContent, OwnedUserId};
use matrix_sdk::ruma::{events::room::message::RoomMessageEventContent, OwnedUserId, UserId};
use readable::up::{Uptime, UptimeFull};
use tracing::{info, instrument, trace};

use crate::{
command::Command,
constants::{
CONFIG, CUPRATE_GITHUB_PULL, CUPRATE_MEETING_UTC_HOUR, CUPRATE_MEETING_WEEKDAY, HELP,
INIT_INSTANT, MOO, TXT_EMPTY, TXT_MEETING_START_IDENT,
CONFIG, CUPRATE_GITHUB_PULL, CUPRATE_MEETING_MODERATOR_MATRIX_ID, CUPRATE_MEETING_UTC_HOUR,
CUPRATE_MEETING_WEEKDAY, HELP, INIT_INSTANT, MOO, TXT_EMPTY, TXT_MEETING_START_IDENT,
},
database::Database,
github::pr_is_open,
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Command {
Self::Sweep => Self::handle_sweep(db).await,
Self::Sweeper => Self::handle_sweeper(db).await,
Self::Clear => Self::handle_clear(db).await,
Self::Meeting => Self::handle_meeting().await,
Self::Meeting => Self::handle_meeting(&user).await,
Self::Agenda(items) => Self::handle_agenda(items).await,
Self::Status => Self::handle_status(),
Self::Help => Self::handle_help(),
Expand Down Expand Up @@ -314,7 +314,17 @@ impl Command {

/// TODO
#[instrument]
async fn handle_meeting() -> RoomMessageEventContent {
async fn handle_meeting(user: &UserId) -> RoomMessageEventContent {
// Only the moderator should be able to start/end the meeting.
if user != *CUPRATE_MEETING_MODERATOR_MATRIX_ID {
let msg = format!(
"You are not the meeting moderator ({CUPRATE_MEETING_MODERATOR_MATRIX_ID:?})"
);
info!(msg);
return RoomMessageEventContent::text_plain(msg);
}

// Check if it is the right date/time.
{
use chrono::prelude::*;
let now = chrono::Utc::now();
Expand All @@ -332,6 +342,7 @@ impl Command {
}
}

// If the meeting is on-going, end it.
let msg = if MEETING_ONGOING.load(Ordering::Acquire) {
let mut logs = String::new();
let mut db = MEETING_DATABASE.lock().await;
Expand All @@ -345,6 +356,7 @@ impl Command {
}
Err(e) => e.to_string(),
}
// Else, start it.
} else {
let mut db = MEETING_DATABASE.lock().await;
*db = String::from("## Meeting logs");
Expand Down
29 changes: 16 additions & 13 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{hint::black_box, path::PathBuf, time::Instant};

use const_format::formatcp;
use matrix_sdk::{
ruma::{user_id, OwnedRoomId, OwnedUserId, RoomId},
ruma::{owned_user_id, room_id, user_id, OwnedUserId, RoomId, UserId},
Client, Room,
};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -65,28 +65,31 @@ pub const MOO_USER_AGENT: &str = concat!("moo", "/", env!("CARGO_PKG_VERSION"),)

//---------------------------------------------------------------------------------------------------- Matrix Rooms
/// Cuprate's Matrix room ID.
pub static CUPRATE_MATRIX_ROOM_ID: Lazy<OwnedRoomId> =
Lazy::new(|| RoomId::parse("!zPLCnZSsyeFFxUiqUZ:monero.social").unwrap());
pub static CUPRATE_MATRIX_ROOM_ID: Lazy<&RoomId> =
Lazy::new(|| room_id!("!zPLCnZSsyeFFxUiqUZ:monero.social"));

// /// Test Matrix room ID.
// pub static CUPRATE_MATRIX_ROOM_ID: Lazy<OwnedRoomId> =
// Lazy::new(|| RoomId::parse("!SrjNVhHuHOWcFfYRfj:monero.social").unwrap());
// pub static CUPRATE_MATRIX_ROOM_ID: Lazy<&RoomId> =
// Lazy::new(|| room_id!("!SrjNVhHuHOWcFfYRfj:monero.social"));

//---------------------------------------------------------------------------------------------------- IDs
/// TODO
pub const MOO_GITHUB_ID: &str = "moo900";

/// TODO
pub static MOO_MATRIX_ID: Lazy<OwnedUserId> =
Lazy::new(|| user_id!("@moo:monero.social").to_owned());
pub static MOO_MATRIX_ID: Lazy<&UserId> = Lazy::new(|| user_id!("@moo:monero.social"));

/// TODO
pub static ALLOWED_MATRIX_IDS_DEFAULT: Lazy<Vec<OwnedUserId>> = Lazy::new(|| {
vec![
user_id!("@hinto:monero.social").to_owned(),
user_id!("@boog900:monero.social").to_owned(),
user_id!("@syntheticbird:monero.social").to_owned(),
user_id!("@yamabiiko:unitoo.it").to_owned(),
pub static CUPRATE_MEETING_MODERATOR_MATRIX_ID: Lazy<&UserId> =
Lazy::new(|| user_id!("@boog900:monero.social"));

/// TODO
pub static ALLOWED_MATRIX_IDS_DEFAULT: Lazy<[OwnedUserId; 4]> = Lazy::new(|| {
[
owned_user_id!("@hinto:monero.social"),
owned_user_id!("@boog900:monero.social"),
owned_user_id!("@syntheticbird:monero.social"),
owned_user_id!("@yamabiiko:unitoo.it"),
]
});

Expand Down

0 comments on commit c2622af

Please sign in to comment.