about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs
index 4301ca9..a10cf23 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -51,14 +51,11 @@ async fn main() -> anyhow::Result<()> {
 		.build();
 
 	let iclient = http.interaction(Id::new(APP_ID));
-	let commands_vec = commands(&iclient).await;
+	let commands_vec = commands().await;
 	iclient.set_global_commands(&commands_vec).await.unwrap();
 
 	println!("Set commands!");
 
-	let cmd_ap = commands_vec[1].clone();
-	let cmd_ap_id = cmd_ap.id;
-
 	let cmd_ap_global = iclient
 		.global_commands()
 		.await
@@ -68,7 +65,14 @@ async fn main() -> anyhow::Result<()> {
 		.unwrap();
 
 	for cmd in cmd_ap_global {
-		println!("got appoints global? {}: {}", cmd.name, cmd.description);
+		println!(
+			"global commeand- [{}] {}: {}",
+			cmd.id
+				.map(|c| c.get().to_string())
+				.unwrap_or("-".to_owned()),
+			cmd.name,
+			cmd.description
+		);
 	}
 
 	while let Some(item) = shard.next_event(EventTypeFlags::all()).await {
@@ -99,7 +103,7 @@ async fn handle_event(
 
 				let command = match cmd.name.as_str() {
 					"leaderboard" => Commands::Leaderboard,
-					"addpoints" => Commands::AddPoints,
+					"points" => Commands::Points,
 					_ => panic!("meow"),
 				};
 
@@ -115,7 +119,7 @@ async fn handle_event(
 	Ok(())
 }
 
-async fn commands(ic: &InteractionClient<'_>) -> Vec<Command> {
+async fn commands() -> Vec<Command> {
 	let leaderboard = CommandBuilder::new(
 		"leaderboard",
 		"View the server leaderboard",
@@ -123,18 +127,16 @@ async fn commands(ic: &InteractionClient<'_>) -> Vec<Command> {
 	)
 	.build();
 
-	let addpoints = CommandBuilder::new(
-		"addpoints",
-		"Give someone, or multiple people, points!",
-		CommandType::ChatInput,
-	)
-	.option(IntegerBuilder::new("points", "number of points").required(true))
-	.option(StringBuilder::new("users", "person to give the points").required(true))
-	.validate()
-	.unwrap()
-	.build();
+	let points = CommandBuilder::new("points", "Add and remove points!", CommandType::ChatInput)
+		.option(IntegerBuilder::new("points", "number of points. - or +").required(true))
+		.option(
+			StringBuilder::new("users", "mention people to modify their points!!").required(true),
+		)
+		.validate()
+		.unwrap()
+		.build();
 
-	vec![leaderboard, addpoints]
+	vec![leaderboard, points]
 }
 
 async fn command_handler(
@@ -160,7 +162,7 @@ async fn command_handler(
 				.await
 				.unwrap();
 		}
-		Commands::AddPoints => {
+		Commands::Points => {
 			let data = add_points(&db, &http, guild, command_data).await;
 
 			let response = InteractionResponse {
@@ -237,19 +239,25 @@ async fn add_points(
 		}
 	}
 
+	let (points, points_display, points_verb) = match points {
+		Some(p) if p > 0 => (p, p, "added to"),
+		Some(p) if p <= 0 => (p, -p, "removed from"),
+		Some(_) | None => unreachable!(),
+	};
+
 	if db.get_leaderboard(guild.get()).is_err() {
 		db.create_leaderboard(guild.get()).unwrap();
 	}
 
 	for user in &users {
-		match db.give_user_points(guild.get(), user.get(), points.unwrap()) {
+		match db.give_user_points(guild.get(), user.get(), points) {
 			Err(DbError::UserNotExist) => {
 				let member = aumau!(http.guild_member(guild, *user));
 				let row = BoardRow {
 					user_id: user.get(),
 					user_handle: member.user.name,
 					user_nickname: member.nick.or(member.user.global_name),
-					points: points.unwrap(),
+					points,
 				};
 				db.add_user_to_leaderboard(guild.get(), row).unwrap();
 			}
@@ -263,17 +271,16 @@ async fn add_points(
 		.collect::<Vec<String>>()
 		.join(", ");
 
+	let msg = format!("{points_display} points {points_verb} {users_string}");
+	let embed = EmbedBuilder::new().description(msg).build();
 	InteractionResponseDataBuilder::new()
-		.content(format!(
-			"added {} points to {users_string}",
-			points.unwrap()
-		))
+		.embeds([embed])
 		.build()
 }
 
 enum Commands {
 	Leaderboard,
-	AddPoints,
+	Points,
 }
 
 fn extract_mentions(mut raw: &str) -> Vec<Id<UserMarker>> {