Skip to content

Commit c05ce62

Browse files
committed
Clean up commands, add usage back etc
1 parent 913a2a4 commit c05ce62

File tree

19 files changed

+178
-215
lines changed

19 files changed

+178
-215
lines changed

bot/src/commands/activities_command.rs

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::{
33
actors::bot_actor::{ActorUpdateMessage, Format, Notify, SendMessageReply},
44
commands::{admin_check, match_command},
5-
BotCommand,
5+
render_template_or_err, BotCommand,
66
},
77
entity::{activities, activityshortcuts},
88
itertools::Itertools,
@@ -16,40 +16,9 @@ use {
1616
command_actor!(ActivitiesCommand, [ActorUpdateMessage]);
1717

1818
impl ActivitiesCommand {
19-
async fn activities_usage(&self, message: &ActorUpdateMessage) {
20-
self.send_reply(
21-
message,
22-
"Activities command help:
23-
24-
/activities
25-
Lists all available activities shortcuts.
26-
27-
Admin-only mode:
28-
29-
/activities ids
30-
Lists IDs of all activities.
31-
/activities add KV
32-
Create new activity from KV pairs (see below).
33-
/activities edit ID KV
34-
Modify activity with given ID by updating all given KVs.
35-
/activities addsc ID shortcut <Game Name>
36-
Add activity shortcut for activity ID.
37-
/activities delete ID
38-
Remove activity if it doesn't have any activities planned.
39-
40-
KV pairs are space-separated pairs of key=value elements
41-
String arguments may be in quotes, but this is optional.
42-
43-
Supported KV pairs for add/edit commands:
44-
45-
name=activity name (e.g. Crucible) <mandatory>
46-
mode=activity mode (e.g. Iron Banner) <optional>
47-
min_fireteam_size=n <mandatory>
48-
max_fireteam_size=n <mandatory>
49-
min_light=n <optional>
50-
min_level=n <optional>",
51-
)
52-
.await;
19+
async fn usage(&self, message: &ActorUpdateMessage) {
20+
self.send_reply(message, render_template_or_err!("activities/usage"))
21+
.await;
5322
}
5423
}
5524

@@ -63,7 +32,9 @@ impl BotCommand for ActivitiesCommand {
6332
}
6433
}
6534

66-
// Need to find a way to partially implement the Actor trait here, esp to set up sub-command actors
35+
// Need to find a way to partially implement the Actor trait here,
36+
// > esp to set up sub-command actors
37+
//
6738
// impl Actor for ActivitiesCommand {
6839
// // Create subcommand actors somewhere here...
6940
//
@@ -84,12 +55,6 @@ impl Message<ActorUpdateMessage> for ActivitiesCommand {
8455
message: ActorUpdateMessage,
8556
_ctx: &mut Context<Self, Self::Reply>,
8657
) -> Self::Reply {
87-
self.handle_message(message).await;
88-
}
89-
}
90-
91-
impl ActivitiesCommand {
92-
async fn handle_message(&self, message: ActorUpdateMessage) {
9358
let connection = self.connection();
9459
if let (Some(_), args) =
9560
match_command(message.update.text(), Self::prefix(), &self.bot_name)
@@ -145,7 +110,7 @@ impl ActivitiesCommand {
145110
let args: Vec<&str> = args.splitn(2, ' ').collect();
146111

147112
if args.is_empty() {
148-
self.activities_usage(&message).await;
113+
self.usage(&message).await;
149114
return;
150115
}
151116

@@ -178,7 +143,7 @@ impl ActivitiesCommand {
178143
if args.len() < 2 {
179144
self.send_reply(&message, "Syntax: /activities add KV")
180145
.await;
181-
return self.activities_usage(&message).await;
146+
return self.usage(&message).await;
182147
}
183148

184149
let argmap = parse_kv_args(args[1]);
@@ -333,7 +298,7 @@ impl ActivitiesCommand {
333298
if args.len() < 2 {
334299
self.send_reply(&message, "Syntax: /activities edit ID KV")
335300
.await;
336-
return self.activities_usage(&message).await;
301+
return self.usage(&message).await;
337302
}
338303

339304
let args: Vec<&str> = args[1].splitn(2, ' ').collect();
@@ -441,7 +406,7 @@ impl ActivitiesCommand {
441406
if args.len() < 2 {
442407
self.send_reply(&message, "Syntax: /activities delete ID")
443408
.await;
444-
return self.activities_usage(&message).await;
409+
return self.usage(&message).await;
445410
}
446411

447412
let id = args[1].parse::<i32>();
@@ -480,7 +445,7 @@ impl ActivitiesCommand {
480445
_ => {
481446
self.send_reply(&message, "Unknown activities operation")
482447
.await;
483-
self.activities_usage(&message).await;
448+
self.usage(&message).await;
484449
}
485450
}
486451
}

bot/src/commands/cancel_command.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::{
33
actors::bot_actor::ActorUpdateMessage,
44
commands::{decapitalize, match_command, validate_username},
5-
BotCommand,
5+
render_template_or_err, BotCommand,
66
},
77
chrono::Duration,
88
entity::{plannedactivities, plannedactivitymembers},
@@ -15,11 +15,8 @@ command_actor!(CancelCommand, [ActorUpdateMessage]);
1515

1616
impl CancelCommand {
1717
async fn cancel_usage(&self, message: &ActorUpdateMessage) {
18-
self.send_reply(
19-
message,
20-
"Cancel command help:\n\n/cancel ActivityID\n Leave planned activity by its number.",
21-
)
22-
.await;
18+
self.send_reply(message, render_template_or_err!("cancel/usage"))
19+
.await;
2320
}
2421
}
2522

@@ -41,12 +38,6 @@ impl Message<ActorUpdateMessage> for CancelCommand {
4138
message: ActorUpdateMessage,
4239
_ctx: &mut Context<Self, Self::Reply>,
4340
) -> Self::Reply {
44-
self.handle_message(message).await;
45-
}
46-
}
47-
48-
impl CancelCommand {
49-
async fn handle_message(&self, message: ActorUpdateMessage) {
5041
let connection = self.connection();
5142

5243
if let (Some(_), activity_id) =
@@ -111,6 +102,7 @@ impl CancelCommand {
111102
.await;
112103
}
113104

105+
// TODO: Claude butchered code here too..
114106
// Get activity name - simplified for now
115107
let act_name = format!("Activity {}", planned.activity_id);
116108
let act_time = decapitalize(&format_start_time(

bot/src/commands/chatid_command.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ impl Message<ActorUpdateMessage> for ChatidCommand {
2121
_ctx: &mut Context<Self, Self::Reply>,
2222
) -> Self::Reply {
2323
if let (Some(_), _) = match_command(msg.update.text(), Self::prefix(), &self.bot_name) {
24-
let _ = self
25-
.send_reply(&msg, format!("ChatId: {}", msg.update.chat.id))
24+
self.send_reply(&msg, format!("Current chat id: {}", msg.update.chat.id))
2625
.await;
2726
}
2827
}

bot/src/commands/dweek_command.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ impl Message<ActorUpdateMessage> for D1weekCommand {
2929
_ctx: &mut Context<Self, Self::Reply>,
3030
) -> Self::Reply {
3131
if let (Some(_), _) = match_command(message.update.text(), Self::prefix(), &self.bot_name) {
32-
let _ = self
33-
.send_reply_with_format(&message, this_week_in_d1(), Format::Markdown)
32+
self.send_reply_with_format(&message, this_week_in_d1(), Format::Markdown)
3433
.await;
3534
}
3635
}

bot/src/commands/edit_command.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::{
33
actors::bot_actor::ActorUpdateMessage,
44
commands::{match_command, validate_username},
5-
BotCommand,
5+
render_template_or_err, BotCommand,
66
},
77
chrono::{prelude::*, Duration},
88
chrono_tz::Europe::Moscow,
@@ -15,23 +15,9 @@ use {
1515
command_actor!(EditCommand, [ActorUpdateMessage]);
1616

1717
impl EditCommand {
18-
async fn edit_usage(&self, message: &ActorUpdateMessage) {
19-
self.send_reply(
20-
message,
21-
"Edit command help:
22-
/edit ActivityID time <new time>
23-
Change scheduled time for activity. Time format examples:
24-
\"tomorrow at 21:00\" or \"Friday at 9 pm\" or \"21:00\"
25-
26-
/edit ActivityID details <new description>
27-
Change details/description for activity.
28-
Use 'delete' as description to remove details.
29-
30-
/edit ActivityID activity <new activity shortcut>
31-
Change type of activity, list of shortcuts
32-
is available from output of /activities command",
33-
)
34-
.await;
18+
async fn usage(&self, message: &ActorUpdateMessage) {
19+
self.send_reply(message, render_template_or_err!("edit/usage"))
20+
.await;
3521
}
3622
}
3723

@@ -53,25 +39,19 @@ impl Message<ActorUpdateMessage> for EditCommand {
5339
message: ActorUpdateMessage,
5440
_ctx: &mut Context<Self, Self::Reply>,
5541
) -> Self::Reply {
56-
self.handle_message(message).await;
57-
}
58-
}
59-
60-
impl EditCommand {
61-
async fn handle_message(&self, message: ActorUpdateMessage) {
6242
let connection = self.connection();
6343

6444
if let (Some(_), args) =
6545
match_command(message.update.text(), Self::prefix(), &self.bot_name)
6646
{
6747
if args.is_none() {
68-
return self.edit_usage(&message).await;
48+
return self.usage(&message).await;
6949
}
7050
let args = args.unwrap();
7151

7252
let args: Vec<_> = args.splitn(3, ' ').collect();
7353
if args.len() != 3 {
74-
return self.edit_usage(&message).await;
54+
return self.usage(&message).await;
7555
}
7656

7757
if validate_username(&self.bot_ref, &message, connection)
@@ -190,7 +170,7 @@ impl EditCommand {
190170
self.send_reply(&message, "Activity type updated.").await;
191171
}
192172
_ => {
193-
self.edit_usage(&message).await;
173+
self.usage(&message).await;
194174
}
195175
}
196176
}

bot/src/commands/editguar_command.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::{
33
actors::bot_actor::ActorUpdateMessage,
44
commands::{admin_check, guardian_lookup, match_command, validate_username},
5-
BotCommand,
5+
render_template_or_err, BotCommand,
66
},
77
entity::guardians,
88
kameo::message::Context,
@@ -12,15 +12,9 @@ use {
1212
command_actor!(EditGuardianCommand, [ActorUpdateMessage]);
1313

1414
impl EditGuardianCommand {
15-
async fn editguar_usage(&self, message: &ActorUpdateMessage) {
16-
self.send_reply(
17-
message,
18-
"Edit guardian command help:
19-
20-
/editguar @Telegram NewPsnName
21-
Change a guardian's PSN name (admin-only).",
22-
)
23-
.await;
15+
async fn usage(&self, message: &ActorUpdateMessage) {
16+
self.send_reply(message, render_template_or_err!("editguar/usage"))
17+
.await;
2418
}
2519
}
2620

@@ -42,19 +36,13 @@ impl Message<ActorUpdateMessage> for EditGuardianCommand {
4236
message: ActorUpdateMessage,
4337
_ctx: &mut Context<Self, Self::Reply>,
4438
) -> Self::Reply {
45-
self.handle_message(message).await;
46-
}
47-
}
48-
49-
impl EditGuardianCommand {
50-
async fn handle_message(&self, message: ActorUpdateMessage) {
5139
let connection = self.connection();
5240

5341
if let (Some(_), args) =
5442
match_command(message.update.text(), Self::prefix(), &self.bot_name)
5543
{
5644
if args.is_none() {
57-
return self.editguar_usage(&message).await;
45+
return self.usage(&message).await;
5846
}
5947

6048
// Split args in two or three:
@@ -65,7 +53,7 @@ impl EditGuardianCommand {
6553
let args: Vec<&str> = args.splitn(3, ' ').collect();
6654

6755
if args.is_empty() || args.len() == 2 {
68-
return self.editguar_usage(&message).await;
56+
return self.usage(&message).await;
6957
}
7058

7159
let name = args[0];
@@ -80,19 +68,19 @@ impl EditGuardianCommand {
8068
let admin = admin_check(&self.bot_ref, &message, connection).await;
8169

8270
if admin.is_none() {
83-
return self.send_reply(&message, "You are not admin").await;
71+
return self.send_reply(&message, "You are not admin").await;
8472
}
8573

8674
let guardian = guardian_lookup(name, connection).await;
8775
let guardian = match guardian {
8876
Ok(Some(guardian)) => Some(guardian),
8977
Ok(None) => {
90-
self.send_reply(&message, format!("Guardian {} was not found.", &name))
78+
self.send_reply(&message, format!("Guardian {} was not found.", &name))
9179
.await;
9280
None
9381
}
9482
Err(_) => {
95-
self.send_reply(&message, "Error querying guardian by name.")
83+
self.send_reply(&message, "Error querying guardian by name.")
9684
.await;
9785
None
9886
}
@@ -132,9 +120,10 @@ impl EditGuardianCommand {
132120
let mut guardian: guardians::ActiveModel = guardian.into();
133121
guardian.psn_name = Set(value.to_string());
134122
if guardian.update(connection).await.is_err() {
135-
return self.send_reply(&message, "Failed to update PSN").await;
123+
return self.send_reply(&message, "Failed to update PSN").await;
136124
}
137-
self.send_reply(&message, "PSN updated successfully").await;
125+
self.send_reply(&message, "✅ PSN updated successfully")
126+
.await;
138127
}
139128
"clan" => {
140129
let clan_value = if value == "delete" {
@@ -145,9 +134,9 @@ impl EditGuardianCommand {
145134
let mut guardian: guardians::ActiveModel = guardian.into();
146135
guardian.psn_clan = Set(clan_value);
147136
if guardian.update(connection).await.is_err() {
148-
return self.send_reply(&message, "Failed to update clan").await;
137+
return self.send_reply(&message, "Failed to update clan").await;
149138
}
150-
self.send_reply(&message, "Updated guardian clan").await;
139+
self.send_reply(&message, "Updated guardian clan").await;
151140
}
152141
"email" => {
153142
let email_value = if value == "delete" {
@@ -158,12 +147,13 @@ impl EditGuardianCommand {
158147
let mut guardian: guardians::ActiveModel = guardian.into();
159148
guardian.email = Set(email_value);
160149
if guardian.update(connection).await.is_err() {
161-
return self.send_reply(&message, "Failed to update email").await;
150+
return self.send_reply(&message, "Failed to update email").await;
162151
}
163-
self.send_reply(&message, "Updated guardian email").await;
152+
self.send_reply(&message, "Updated guardian email").await;
164153
}
165154
_ => {
166-
self.send_reply(&message, "Unknown information field").await;
155+
self.send_reply(&message, "⁉️ Unknown information field")
156+
.await;
167157
}
168158
}
169159
}

0 commit comments

Comments
 (0)