Skip to content

Commit 42e4729

Browse files
committed
feat: Display command usage
Send command usage when it is not entered properly.
1 parent 8a4ef82 commit 42e4729

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

bot.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@
2929
$logger.info("Message from #{event.user.name} (#{event.user.id})")
3030
$logger.info(event.message.content)
3131

32-
if /(?<trigger>!moderation)\s(?<command>watchlist)(\s(?<subcommand>add|remove)\s<@(?<user_id>\d+)>)?/i =~ event.message.content
32+
if /(?<trigger>!moderation)(\s(?<command>watchlist))?(\s(?<subcommand>add|remove)\s<@(?<user_id>\d+)>)?/i =~ event.message.content
3333
$logger.info("Moderation command from #{event.user.name} (#{event.user.id})")
3434
event.server.members.each do |member|
3535
# ensure triggering user has proper privileges
3636
if member.id == event.user.id && member.permission?(:administrator)
3737
# handle watchlist commands
38-
if trigger && command == "watchlist" && subcommand.nil?
39-
event.respond("Watch list: " + get_watch_list_users(event.server.id).map { |user_id| "<@#{user_id}>" }.join(", "))
40-
elsif subcommand == "add" && user_id
41-
add_user_to_watch_list(event.server.id, user_id.to_i)
42-
event.respond("Added <@#{user_id}> to watch list")
43-
elsif subcommand == "remove" && user_id
44-
remove_user_from_watch_list(event.server.id, user_id.to_i)
45-
event.respond("Removed <@#{user_id}> from watch list")
38+
if trigger && command == "watchlist"
39+
if subcommand.nil?
40+
event.respond("Watch list: " + get_watch_list_users(event.server.id).map { |user_id| "<@#{user_id}>" }.join(", "))
41+
elsif subcommand == "add" && user_id
42+
add_user_to_watch_list(event.server.id, user_id.to_i)
43+
event.respond("Added <@#{user_id}> to watch list")
44+
elsif subcommand == "remove" && user_id
45+
remove_user_from_watch_list(event.server.id, user_id.to_i)
46+
event.respond("Removed <@#{user_id}> from watch list")
47+
else
48+
event.respond("Usage: !moderation watchlist [add|remove @user]")
49+
end
4650
else
51+
event.respond("Usage: !moderation watchlist [add|remove @user]")
4752
end
4853
# break early if we found the right user
4954
break

0 commit comments

Comments
 (0)