Sha256: ec3efea564319cc59aead93abdbaf3b752d13c442674a5c18ed30543be13b257

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

class SlackSmartBot
  # help: ----------------------------------------------
  # help: `delete shortcut NAME`
  # help: `delete sc NAME`
  # help:    It will delete the shortcut with the supplied name
  # help:

  def delete_shortcut(dest, from, shortcut, typem, command)
    unless typem == :on_extended
      deleted = false

      if !ADMIN_USERS.include?(from) and @shortcuts[:all].include?(shortcut) and !@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
            (ADMIN_USERS.include?(from) and @shortcuts[:all].include?(shortcut))
        #are you sure? to avoid deleting by mistake
        unless @questions.keys.include?(from)
          ask("are you sure you want to delete it?", command, from, dest)
        else
          case @questions[from]
          when /^(yes|yep)/i
            @questions.delete(from)
            respond "shortcut deleted!", dest
            respond("#{shortcut}: #{@shortcuts[from][shortcut]}", dest) if @shortcuts.key?(from) and @shortcuts[from].key?(shortcut)
            respond("#{shortcut}: #{@shortcuts[:all][shortcut]}", dest) if @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
            @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
            @questions.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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack-smart-bot-1.0.2 lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb
slack-smart-bot-1.0.1 lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb
slack-smart-bot-1.0.0 lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb