Skip to content

Commit 8622754

Browse files
committed
IMPROVE: error handling wrt message number
1 parent 25e2089 commit 8622754

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

config/locales/server.en.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ en:
3030
found_matching_discourse_topic: "SUCCESS: Found matching Discourse Topic"
3131
final_outcome: "SUCCESS: Copied over %{count} past messages to Discourse!"
3232
error:
33-
must_specify_message_number: "ERROR: In outside of a Thread you must specify number of messages to be copied!"
33+
must_specify_message_number: "ERROR: Outside of a Thread you must specify number of messages to be copied!"
34+
must_specify_message_number_as_integer: "ERROR: Number of messages must be an integer!"
3435
unable_to_find_discourse_category: "ERROR: Unable to find matching Discourse Category, aborting command! Be sure to substitute _ for spaces in name and match case."
3536
unable_to_find_discourse_topic: "ERROR: Unable to find matching Discourse Topic in target Category, will create new!"
3637
unable_to_determine_topic_id: "ERROR: Unable to determine a suitable Topic Id for Discourse!"

lib/bot_commands.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ def self.manage_discord_commands(bot)
1717
bot.command(:disccopy, min_args: 0, max_args: 3, bucket: :admin_tasks, rate_limit_message: I18n.t("discord_bot.commands.rate_limit_breached"), required_roles: [SiteSetting.discord_bot_admin_role_id], description: I18n.t("disccopy.description")) do |event, number_of_past_messages, target_category, target_topic|
1818
past_messages = []
1919

20-
if !THREAD_TYPES.include?(event.channel.type) && number_of_past_messages.nil?
21-
event.respond I18n.t("discord_bot.commands.disccopy.error.must_specify_message_number")
22-
break
20+
if !THREAD_TYPES.include?(event.channel.type)
21+
if !(number_of_past_messages.to_i > 0)
22+
event.respond I18n.t("discord_bot.commands.disccopy.error.must_specify_message_number")
23+
break
24+
end
25+
else
26+
if !number_of_past_messages.blank? && !(number_of_past_messages.to_i > 0)
27+
event.respond I18n.t("discord_bot.commands.disccopy.error.must_specify_message_number_as_integer")
28+
break
29+
end
2330
end
2431

2532
number_of_past_messages = number_of_past_messages || HISTORY_CHUNK_LIMIT

plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
# name: discourse-discord-bot
33
# about: Integrate Discord Bots with Discourse
4-
# version: 0.3.2
4+
# version: 0.3.3
55
# authors: Robert Barrow
66
# url: https://github.com/merefield/discourse-discord-bot
77

0 commit comments

Comments
 (0)