Skip to content

Commit

Permalink
delete message command close #32
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRuiz committed Sep 22, 2021
1 parent ff432b5 commit 5e15a78
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/slack/smart-bot/comm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
require_relative 'comm/event_hello'
require_relative 'comm/get_channel_members'
require_relative 'comm/get_channels'
require_relative 'comm/delete'
13 changes: 13 additions & 0 deletions lib/slack/smart-bot/comm/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class SlackSmartBot
def delete(channel, ts)
result = true
begin
resp = client.web_client.chat_delete(channel: channel, as_user: true, ts: ts)
result = resp.ok.to_s == 'true'
rescue Exception => exc
result = false
@logger.fatal exc.inspect
end
return result
end
end
1 change: 1 addition & 0 deletions lib/slack/smart-bot/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
require_relative "commands/on_extended/bot_rules"
require_relative "commands/on_bot/admin_master/get_bot_logs"
require_relative "commands/on_bot/admin_master/send_message"
require_relative "commands/on_bot/admin_master/delete_message"
require_relative "commands/on_bot/admin_master/react_to"
require_relative "commands/general/bot_stats"
require_relative "commands/general/leaderboard"
Expand Down
24 changes: 24 additions & 0 deletions lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class SlackSmartBot

# helpadmin: ----------------------------------------------
# helpadmin: `delete message URL`
# helpadmin: It will delete the SmartBot message supplied
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
# helpadmin:
def delete_message(from, typem, url)
save_stats(__method__)
channel, ts = url.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
if config.masters.include?(from) and typem==:on_dm and !channel.nil? #master admin user
ts = "#{ts[0..-7]}.#{ts[-6..-1]}"
succ = delete(channel, ts)
if succ
react :heavy_check_mark
else
react :x
end
else
respond "Only master admin users on a private conversation with the SmartBot can delete SmartBot messages"
end
end
end

3 changes: 3 additions & 0 deletions lib/slack/smart-bot/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def process(user, command, dest, dchannel, rules_file, typem, files, ts)
to = to_channel
end
send_message(dest, from, typem, to, thread_ts, message)
when /\A\s*delete\s+message\s+(.+)\s*$/i
url = $1
delete_message(from, typem, url)
when /\A\s*react\s+(on|to|in)\s*([^\s]+)\s+([^\s]+)\s+(.+)\s*$/i
to = $2
thread_ts = $3.to_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
save_stats :which_rules
respond "bot1cm"
react :thumbsup

when /^test silent (.+)$/i
tempo = $1
if Time.now.to_s > tempo
Expand Down

0 comments on commit 5e15a78

Please sign in to comment.