Sha256: 8056e7ef899ae5f854dcf039d546286b320d594e78eeb82e0d0d659e87af5d18

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

class SlackSmartBot
  # helpmaster: ----------------------------------------------
  # helpmaster: `kill bot on CHANNEL_NAME`
  # helpmaster:    kills the bot on the specified channel
  # helpmaster:    Only works if you are on Master channel and you created that bot or you are an admin user
  # helpmaster:
  def kill_bot_on_channel(dest, from, channel)
    if ON_MASTER_BOT
      get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
      channel_id = nil
      if @channels_name.key?(channel) #it is an id
        channel_id = channel
        channel = @channels_name[channel_id]
      elsif @channels_id.key?(channel) #it is a channel name
        channel_id = @channels_id[channel]
      end
      if channel_id.nil?
        respond "There is no channel with that name: #{channel}, please be sure is written exactly the same", dest
      elsif @bots_created.keys.include?(channel_id)
        if @bots_created[channel_id][:admins].split(",").include?(from)
          if @bots_created[channel_id][:thread].kind_of?(Thread) and @bots_created[channel_id][:thread].alive?
            @bots_created[channel_id][:thread].kill
          end
          @bots_created.delete(channel_id)
          update_bots_file()
          respond "Bot on channel: #{channel}, has been killed and deleted.", dest
          send_msg_channel(channel, "Bot has been killed by #{from}")
        else
          respond "You need to be the creator or an admin of that bot channel", dest
        end
      else
        respond "There is no bot in this channel: #{channel}", dest
      end
    else
      respond "Sorry I cannot kill bots from this channel, please visit the master channel: <##{@master_bot_id}>", dest
    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_master/admin/kill_bot_on_channel.rb
slack-smart-bot-1.0.1 lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb
slack-smart-bot-1.0.0 lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb