class SlackSmartBot
def delete_shortcut(dest, user, shortcut, typem, command, global)
save_stats(__method__)
unless typem == :on_extended
from = user.name
if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
else
deleted = false
if global
if !config.on_master_bot or typem != :on_master
respond "It is only possible to delete global shortcuts from Master channel"
else
if !config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut) and
(!@shortcuts_global.key?(from) or !@shortcuts_global[from].include?(shortcut))
respond "Only the creator of the shortcut or an admin user can delete it"
elsif (@shortcuts_global.key?(from) and @shortcuts_global[from].keys.include?(shortcut)) or
(config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut))
respond "global shortcut deleted!", dest
if @shortcuts_global.key?(from) and @shortcuts_global[from].key?(shortcut)
respond("#{shortcut}: #{@shortcuts_global[from][shortcut]}", dest)
elsif @shortcuts_global.key?(:all) and @shortcuts_global[:all].key?(shortcut)
respond("#{shortcut}: #{@shortcuts_global[:all][shortcut]}", dest)
end
@shortcuts_global[from].delete(shortcut) if @shortcuts_global.key?(from) and @shortcuts_global[from].key?(shortcut)
@shortcuts_global[:all].delete(shortcut) if @shortcuts_global.key?(:all) and @shortcuts_global[:all].key?(shortcut)
update_shortcuts_file()
else
respond 'shortcut not found'
end
end
else
if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut) and
(!@shortcuts.key?(from) or !@shortcuts[from].include?(shortcut))
respond "Only the creator of the shortcut or an admin user can delete it", dest
elsif (@shortcuts.keys.include?(from) and @shortcuts[from].keys.include?(shortcut)) or
(config.admins.include?(from) and @shortcuts[:all].include?(shortcut))
if answer.empty?
ask("are you sure you want to delete it?", command, from, dest)
else
case answer
when /^(yes|yep)/i
answer_delete(from)
respond "shortcut deleted!", dest
if @shortcuts.key?(from) and @shortcuts[from].key?(shortcut)
respond("#{shortcut}: #{@shortcuts[from][shortcut]}", dest)
elsif @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
respond("#{shortcut}: #{@shortcuts[:all][shortcut]}", dest)
end
@shortcuts[from].delete(shortcut) if @shortcuts.key?(from) and @shortcuts[from].key?(shortcut)
@shortcuts[:all].delete(shortcut) if @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
update_shortcuts_file()
when /^no/i
answer_delete(from)
respond "ok, I won't delete it", dest
else
ask("I don't understand, are you sure you want to delete it? (yes or no)", command, from, dest)
end
end
else
respond "shortcut not found", dest
end
end
end
end
end
end